結果

問題 No.843 Triple Primes
ユーザー AT274_
提出日時 2019-10-18 16:45:34
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 536 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 74,112 KB
最終ジャッジ日時 2024-06-25 14:38:55
合計ジャッジ時間 6,894 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

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