結果
| 問題 |
No.732 3PrimeCounting
|
| コンテスト | |
| ユーザー |
PNJ
|
| 提出日時 | 2023-11-21 05:29:30 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 597 bytes |
| コンパイル時間 | 379 ms |
| コンパイル使用メモリ | 82,336 KB |
| 実行使用メモリ | 113,192 KB |
| 最終ジャッジ日時 | 2024-09-26 07:00:50 |
| 合計ジャッジ時間 | 45,952 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 87 TLE * 2 |
ソースコード
from collections import defaultdict
def Eratosthenes(N):
is_prime = [1 for i in range(N+1)]
is_prime[0] = is_prime[1] = 0
P = []
for p in range(2,N+1):
if is_prime[p] == 0:
continue
P.append(p)
for d in range(2,N//p+1):
q = p*d
is_prime[q] = 0
return P
N = int(input())
P = Eratosthenes(300000)
P = P[::-1]
d = defaultdict(int)
Q = []
ans = 0
m = 0
while len(P):
c = P.pop()
if c > N:
break
for p in reversed(P):
if p - c > m:
break
ans += d[p-c]
for p in Q:
d[p+c] += 1
if c >= 3:
m = Q[-1] + c
Q.append(c)
print(ans)
PNJ