結果

問題 No.843 Triple Primes
ユーザー lloyz
提出日時 2022-04-30 00:57:55
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 382 ms / 2,000 ms
コード長 490 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 19,796 KB
最終ジャッジ日時 2024-06-29 06:56:34
合計ジャッジ時間 10,075 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
IsPrime = [True for _ in range(n + 1)]
IsPrime[0] = IsPrime[1] = False
for i in range(2, n + 1):
    if IsPrime[i]:
        for j in range(i + i, n + 1, i):
            IsPrime[j] = False

Primes = []
Prime_square_set = set()
for i in range(n + 1):
    if IsPrime[i]:
        Primes.append(i)
        Prime_square_set.add(i**2)
ans = 0
for p in Primes:
    if p + 2 in Prime_square_set:
        if p == 2:
            ans += 1
        else:
            ans += 2
print(ans)
0