結果

問題 No.843 Triple Primes
ユーザー H20
提出日時 2021-01-07 10:55:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 166 ms / 2,000 ms
コード長 639 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 90,112 KB
最終ジャッジ日時 2024-11-08 00:35:11
合計ジャッジ時間 6,108 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 42
権限があれば一括ダウンロードができます

ソースコード

diff #

def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    return is_prime, table

N = int(input())
_,t = sieve(2*N)
s=set(t)
ppow = []
lent = len(t)
i = 0
while  i<lent and t[i]**2<=2*N:
    ppow.append(t[i]**2)
    i+=1
ans = 0

for p in ppow:
    for j in range(lent):
        if p - t[j] in s and p - t[j]<=N and t[j]<=N:
            ans+=1
        if t[j]>=p:
            break
print(ans)
0