結果

問題 No.732 3PrimeCounting
ユーザー PNJPNJ
提出日時 2023-11-21 05:33:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 526 ms / 3,000 ms
コード長 616 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 76,416 KB
最終ジャッジ日時 2023-11-21 05:33:42
合計ジャッジ時間 13,340 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
71,908 KB
testcase_01 AC 63 ms
71,908 KB
testcase_02 AC 61 ms
71,908 KB
testcase_03 AC 61 ms
71,908 KB
testcase_04 AC 61 ms
71,908 KB
testcase_05 AC 61 ms
71,908 KB
testcase_06 AC 61 ms
71,908 KB
testcase_07 AC 64 ms
71,908 KB
testcase_08 AC 61 ms
71,908 KB
testcase_09 AC 62 ms
71,908 KB
testcase_10 AC 62 ms
71,908 KB
testcase_11 AC 62 ms
71,908 KB
testcase_12 AC 62 ms
71,908 KB
testcase_13 AC 62 ms
71,908 KB
testcase_14 AC 62 ms
71,908 KB
testcase_15 AC 62 ms
71,908 KB
testcase_16 AC 62 ms
71,908 KB
testcase_17 AC 61 ms
71,908 KB
testcase_18 AC 62 ms
71,908 KB
testcase_19 AC 63 ms
71,908 KB
testcase_20 AC 65 ms
74,224 KB
testcase_21 AC 67 ms
74,352 KB
testcase_22 AC 74 ms
74,352 KB
testcase_23 AC 63 ms
72,164 KB
testcase_24 AC 62 ms
72,164 KB
testcase_25 AC 69 ms
74,352 KB
testcase_26 AC 68 ms
74,352 KB
testcase_27 AC 65 ms
74,224 KB
testcase_28 AC 64 ms
74,224 KB
testcase_29 AC 67 ms
74,352 KB
testcase_30 AC 66 ms
74,352 KB
testcase_31 AC 67 ms
74,352 KB
testcase_32 AC 69 ms
74,352 KB
testcase_33 AC 68 ms
74,352 KB
testcase_34 AC 68 ms
74,352 KB
testcase_35 AC 68 ms
74,352 KB
testcase_36 AC 68 ms
74,352 KB
testcase_37 AC 67 ms
74,224 KB
testcase_38 AC 64 ms
74,224 KB
testcase_39 AC 69 ms
74,352 KB
testcase_40 AC 68 ms
74,352 KB
testcase_41 AC 68 ms
74,352 KB
testcase_42 AC 68 ms
74,352 KB
testcase_43 AC 67 ms
74,352 KB
testcase_44 AC 68 ms
74,352 KB
testcase_45 AC 66 ms
74,224 KB
testcase_46 AC 66 ms
74,224 KB
testcase_47 AC 66 ms
74,224 KB
testcase_48 AC 69 ms
74,352 KB
testcase_49 AC 70 ms
74,352 KB
testcase_50 AC 68 ms
74,352 KB
testcase_51 AC 67 ms
74,352 KB
testcase_52 AC 71 ms
74,224 KB
testcase_53 AC 74 ms
74,352 KB
testcase_54 AC 215 ms
74,352 KB
testcase_55 AC 214 ms
74,352 KB
testcase_56 AC 222 ms
74,352 KB
testcase_57 AC 91 ms
74,352 KB
testcase_58 AC 91 ms
74,352 KB
testcase_59 AC 74 ms
74,352 KB
testcase_60 AC 107 ms
74,352 KB
testcase_61 AC 106 ms
74,352 KB
testcase_62 AC 266 ms
74,352 KB
testcase_63 AC 146 ms
74,352 KB
testcase_64 AC 118 ms
74,352 KB
testcase_65 AC 119 ms
74,352 KB
testcase_66 AC 62 ms
71,908 KB
testcase_67 AC 63 ms
71,908 KB
testcase_68 AC 238 ms
74,352 KB
testcase_69 AC 235 ms
74,352 KB
testcase_70 AC 215 ms
74,352 KB
testcase_71 AC 216 ms
74,352 KB
testcase_72 AC 139 ms
74,352 KB
testcase_73 AC 407 ms
74,352 KB
testcase_74 AC 402 ms
74,352 KB
testcase_75 AC 68 ms
74,352 KB
testcase_76 AC 233 ms
74,352 KB
testcase_77 AC 95 ms
74,352 KB
testcase_78 AC 319 ms
74,352 KB
testcase_79 AC 240 ms
74,352 KB
testcase_80 AC 286 ms
74,352 KB
testcase_81 AC 220 ms
74,352 KB
testcase_82 AC 64 ms
74,224 KB
testcase_83 AC 93 ms
74,352 KB
testcase_84 AC 96 ms
74,352 KB
testcase_85 AC 201 ms
74,352 KB
testcase_86 AC 294 ms
74,352 KB
testcase_87 AC 525 ms
76,416 KB
testcase_88 AC 526 ms
76,416 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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]
cout = [0 for i in range(300001)]
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 += cout[p-c]
  for p in Q:
    cout[p+c] += 1
  if c >= 3:
    m = Q[-1] + c
  Q.append(c)
print(ans)
0