結果

問題 No.843 Triple Primes
ユーザー Akisawa0313
提出日時 2021-04-28 11:37:38
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 274 ms / 2,000 ms
コード長 292 bytes
コンパイル時間 81 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 16,316 KB
最終ジャッジ日時 2024-07-07 05:52:51
合計ジャッジ時間 7,413 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())

p = [-1]*(N+1)
L = []
for i in range(2, N+1):
    if p[i] == 0:
        continue
    L.append(i)
    p[i] = 1
    for j in range(2*i, N+1, i):
        p[j] = 0

ans = -1
for r in L:
    if r**2-2 > N:
        break
    if p[r**2-2] == 1:
        ans += 2

print(max(0, ans))
0