結果

問題 No.843 Triple Primes
ユーザー AT274_AT274_
提出日時 2019-10-18 16:45:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 271 ms / 2,000 ms
コード長 536 bytes
コンパイル時間 408 ms
コンパイル使用メモリ 86,780 KB
実行使用メモリ 87,712 KB
最終ジャッジ日時 2023-09-07 20:57:49
合計ジャッジ時間 8,647 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,700 KB
testcase_01 AC 271 ms
87,600 KB
testcase_02 AC 81 ms
76,472 KB
testcase_03 AC 80 ms
76,464 KB
testcase_04 AC 80 ms
76,528 KB
testcase_05 AC 81 ms
76,596 KB
testcase_06 AC 82 ms
76,468 KB
testcase_07 AC 183 ms
84,932 KB
testcase_08 AC 207 ms
86,152 KB
testcase_09 AC 261 ms
87,508 KB
testcase_10 AC 190 ms
84,952 KB
testcase_11 AC 224 ms
86,232 KB
testcase_12 AC 251 ms
87,460 KB
testcase_13 AC 235 ms
86,444 KB
testcase_14 AC 234 ms
86,460 KB
testcase_15 AC 184 ms
84,684 KB
testcase_16 AC 187 ms
84,740 KB
testcase_17 AC 73 ms
71,292 KB
testcase_18 AC 73 ms
71,840 KB
testcase_19 AC 72 ms
71,524 KB
testcase_20 AC 97 ms
78,564 KB
testcase_21 AC 90 ms
77,164 KB
testcase_22 AC 127 ms
81,620 KB
testcase_23 AC 130 ms
82,360 KB
testcase_24 AC 97 ms
78,616 KB
testcase_25 AC 105 ms
77,668 KB
testcase_26 AC 259 ms
87,316 KB
testcase_27 AC 83 ms
76,520 KB
testcase_28 AC 242 ms
86,460 KB
testcase_29 AC 101 ms
78,740 KB
testcase_30 AC 257 ms
87,528 KB
testcase_31 AC 85 ms
76,748 KB
testcase_32 AC 84 ms
76,680 KB
testcase_33 AC 101 ms
78,884 KB
testcase_34 AC 118 ms
81,420 KB
testcase_35 AC 260 ms
87,712 KB
testcase_36 AC 99 ms
77,536 KB
testcase_37 AC 170 ms
84,992 KB
testcase_38 AC 139 ms
82,708 KB
testcase_39 AC 244 ms
87,104 KB
testcase_40 AC 72 ms
71,888 KB
testcase_41 AC 72 ms
71,172 KB
testcase_42 AC 196 ms
85,920 KB
testcase_43 AC 226 ms
86,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())


def eratosthenes(n):
    if n < 2:
        return []

    is_primes = [True] * (n + 1)
    for x in range(2, int(n ** 0.5 + 1) + 1):
        if is_primes[x]:
            for mx in range(2 * x, n + 1, x):
                is_primes[mx] = False

    return [i for i in range(2, n + 1) if is_primes[i]]


primes = eratosthenes(N)
prime_set = set(primes)

ans = 0
for r in primes:
    if r ** 2 > 2 * N:
        break
    for p in primes:
        q = r ** 2 - p
        if q in prime_set:
            ans += 1

print(ans)
0