結果

問題 No.843 Triple Primes
ユーザー yuki2006yuki2006
提出日時 2019-06-27 22:09:34
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 493 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 11,880 KB
実行使用メモリ 13,812 KB
最終ジャッジ日時 2023-10-19 17:27:14
合計ジャッジ時間 4,439 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
10,092 KB
testcase_01 AC 115 ms
13,812 KB
testcase_02 AC 31 ms
10,140 KB
testcase_03 AC 31 ms
10,128 KB
testcase_04 AC 32 ms
10,164 KB
testcase_05 AC 31 ms
10,132 KB
testcase_06 AC 31 ms
10,168 KB
testcase_07 AC 91 ms
13,020 KB
testcase_08 AC 102 ms
13,284 KB
testcase_09 AC 108 ms
13,812 KB
testcase_10 AC 89 ms
13,280 KB
testcase_11 AC 94 ms
13,544 KB
testcase_12 AC 106 ms
13,808 KB
testcase_13 AC 97 ms
13,548 KB
testcase_14 AC 96 ms
13,548 KB
testcase_15 AC 87 ms
13,020 KB
testcase_16 AC 89 ms
13,280 KB
testcase_17 AC 28 ms
10,092 KB
testcase_18 AC 28 ms
10,092 KB
testcase_19 AC 28 ms
10,092 KB
testcase_20 AC 48 ms
10,972 KB
testcase_21 AC 40 ms
10,444 KB
testcase_22 AC 70 ms
12,028 KB
testcase_23 AC 70 ms
12,224 KB
testcase_24 AC 49 ms
10,972 KB
testcase_25 AC 45 ms
10,708 KB
testcase_26 AC 100 ms
13,808 KB
testcase_27 AC 32 ms
10,180 KB
testcase_28 AC 97 ms
13,548 KB
testcase_29 AC 50 ms
11,236 KB
testcase_30 AC 100 ms
13,808 KB
testcase_31 AC 34 ms
10,180 KB
testcase_32 AC 31 ms
10,180 KB
testcase_33 AC 53 ms
11,236 KB
testcase_34 AC 65 ms
12,028 KB
testcase_35 AC 101 ms
13,812 KB
testcase_36 AC 43 ms
10,708 KB
testcase_37 AC 84 ms
13,016 KB
testcase_38 AC 75 ms
12,488 KB
testcase_39 AC 98 ms
13,808 KB
testcase_40 AC 28 ms
10,092 KB
testcase_41 AC 28 ms
10,092 KB
testcase_42 AC 90 ms
13,280 KB
testcase_43 AC 95 ms
13,544 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())


def sieve(N):
    primes = [True] * (N + 1)
    primes[0] = False
    primes[1] = False
    for i in range(2, N + 1):
        if not primes[i]:
            continue
        for j in range(i * i, N + 1, i):
            primes[j] = False
    return primes


isPrimes = sieve(N)
count = 0
r = 2
while r * r <= N + 2:
    k = r * r - 2
    if isPrimes[k] and isPrimes[r]:

        if k == r:
            count += 1
        else:
            count += 2
    r += 1

print(count)

0