結果

問題 No.843 Triple Primes
コンテスト
ユーザー AT274_
提出日時 2019-10-18 16:45:34
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 536 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 437 ms
コンパイル使用メモリ 85,748 KB
実行使用メモリ 76,160 KB
最終ジャッジ日時 2026-03-11 23:14:59
合計ジャッジ時間 4,716 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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