結果

問題 No.732 3PrimeCounting
コンテスト
ユーザー qib
提出日時 2023-01-16 20:34:48
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 554 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 361 ms
コンパイル使用メモリ 84,736 KB
実行使用メモリ 71,040 KB
最終ジャッジ日時 2026-06-04 21:04:58
合計ジャッジ時間 28,342 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 89
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n = int(input())

prime = [True for _ in range(3 * n + 1)]
prime[0] = prime[1] = False
for x in range(2, 3 * n + 1):
  if not prime[x]:
    continue

  for y in range(2 * x, 3 * n + 1, x):
    prime[y] = False

cnt = [0 for _ in range(2 * n + 1)]
primes = []
ans = 0
for x in range(1, n + 1):
  if not prime[x]:
    continue

  if len(primes) < 1:
    primes.append(x)
    continue

  for s in range(x, 2 * primes[-1] + x + 1):
    if prime[s]:
      ans += cnt[s - x]

  for y in primes:
    cnt[x + y] += 1

  primes.append(x)

print("TEST")
print(ans)
0