結果

問題 No.843 Triple Primes
ユーザー ntuda
提出日時 2025-04-08 21:55:43
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 508 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 82,912 KB
実行使用メモリ 79,800 KB
最終ジャッジ日時 2025-04-08 21:55:50
合計ジャッジ時間 5,408 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

def PrimeList(N):
    P = [1] * (N + 1)
    P[0] = P[1] = 0
    for i in range(2, N + 1):
        if P[i]:
            for j in range(i + i, N + 1, i):
                P[j] = 0
    PL = []
    for i in range(N + 1):
        if P[i] == 1:
            PL.append(i)
    return PL

N = int(input())
PL = PrimeList(N)
SPL = set(PL)
ans = 0
for a in PL:
    a2 = a * a
    if a2 > 2 * N:
        break
    for b in PL:
        if b >= a2:
            break
        if a2 - b in SPL:
            ans += 1
print(ans)
0