結果

問題 No.732 3PrimeCounting
コンテスト
ユーザー qib
提出日時 2023-01-16 20:36:33
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 2,180 ms / 3,000 ms
+ 335µs
コード長 540 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 62 ms
コンパイル使用メモリ 81,584 KB
実行使用メモリ 72,744 KB
最終ジャッジ日時 2026-10-09 21:57:47
合計ジャッジ時間 27,086 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 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(ans)
0