結果

問題 No.732 3PrimeCounting
ユーザー PNJPNJ
提出日時 2023-11-21 05:16:29
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 667 bytes
コンパイル時間 321 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 115,364 KB
最終ジャッジ日時 2023-11-21 05:17:17
合計ジャッジ時間 47,557 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
69,504 KB
testcase_01 AC 57 ms
69,504 KB
testcase_02 AC 58 ms
69,504 KB
testcase_03 AC 56 ms
69,504 KB
testcase_04 AC 57 ms
69,504 KB
testcase_05 AC 61 ms
69,504 KB
testcase_06 AC 57 ms
69,504 KB
testcase_07 AC 57 ms
69,504 KB
testcase_08 AC 56 ms
69,504 KB
testcase_09 AC 56 ms
69,504 KB
testcase_10 AC 57 ms
69,504 KB
testcase_11 AC 57 ms
69,504 KB
testcase_12 AC 57 ms
69,504 KB
testcase_13 AC 57 ms
69,504 KB
testcase_14 AC 58 ms
69,504 KB
testcase_15 AC 58 ms
69,504 KB
testcase_16 AC 57 ms
69,504 KB
testcase_17 AC 57 ms
69,504 KB
testcase_18 AC 56 ms
69,504 KB
testcase_19 AC 56 ms
69,504 KB
testcase_20 AC 66 ms
74,000 KB
testcase_21 AC 73 ms
76,068 KB
testcase_22 AC 73 ms
76,068 KB
testcase_23 AC 59 ms
71,896 KB
testcase_24 AC 59 ms
71,896 KB
testcase_25 AC 86 ms
80,164 KB
testcase_26 AC 76 ms
76,324 KB
testcase_27 AC 66 ms
74,000 KB
testcase_28 AC 67 ms
74,000 KB
testcase_29 AC 71 ms
76,068 KB
testcase_30 AC 70 ms
76,068 KB
testcase_31 AC 73 ms
76,068 KB
testcase_32 AC 77 ms
76,708 KB
testcase_33 AC 78 ms
76,836 KB
testcase_34 AC 79 ms
76,836 KB
testcase_35 AC 74 ms
76,068 KB
testcase_36 AC 74 ms
76,068 KB
testcase_37 AC 64 ms
74,000 KB
testcase_38 AC 65 ms
74,000 KB
testcase_39 AC 77 ms
76,068 KB
testcase_40 AC 74 ms
76,068 KB
testcase_41 AC 74 ms
76,068 KB
testcase_42 AC 74 ms
76,068 KB
testcase_43 AC 72 ms
76,068 KB
testcase_44 AC 71 ms
76,068 KB
testcase_45 AC 67 ms
74,000 KB
testcase_46 AC 67 ms
74,000 KB
testcase_47 AC 68 ms
74,000 KB
testcase_48 AC 91 ms
80,164 KB
testcase_49 AC 88 ms
80,164 KB
testcase_50 AC 73 ms
76,068 KB
testcase_51 AC 72 ms
76,068 KB
testcase_52 AC 67 ms
74,000 KB
testcase_53 AC 123 ms
80,164 KB
testcase_54 AC 1,307 ms
91,428 KB
testcase_55 AC 1,301 ms
91,428 KB
testcase_56 AC 1,303 ms
91,428 KB
testcase_57 AC 260 ms
81,316 KB
testcase_58 AC 260 ms
81,316 KB
testcase_59 AC 131 ms
80,164 KB
testcase_60 AC 372 ms
82,212 KB
testcase_61 AC 372 ms
82,212 KB
testcase_62 AC 1,717 ms
94,500 KB
testcase_63 AC 713 ms
84,900 KB
testcase_64 AC 485 ms
82,596 KB
testcase_65 AC 484 ms
82,596 KB
testcase_66 AC 57 ms
69,504 KB
testcase_67 AC 58 ms
69,504 KB
testcase_68 AC 1,487 ms
93,988 KB
testcase_69 AC 1,473 ms
93,988 KB
testcase_70 AC 1,294 ms
91,428 KB
testcase_71 AC 1,304 ms
91,428 KB
testcase_72 AC 659 ms
84,900 KB
testcase_73 AC 2,761 ms
105,252 KB
testcase_74 AC 2,763 ms
105,252 KB
testcase_75 AC 81 ms
77,732 KB
testcase_76 AC 1,440 ms
91,940 KB
testcase_77 AC 282 ms
81,316 KB
testcase_78 AC 2,123 ms
98,468 KB
testcase_79 AC 1,472 ms
93,988 KB
testcase_80 AC 1,926 ms
97,316 KB
testcase_81 AC 1,336 ms
91,428 KB
testcase_82 AC 65 ms
74,000 KB
testcase_83 AC 270 ms
81,316 KB
testcase_84 AC 300 ms
81,700 KB
testcase_85 AC 1,104 ms
89,124 KB
testcase_86 AC 1,932 ms
97,956 KB
testcase_87 TLE -
testcase_88 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
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+1):
      q = p*d
      if q > N:
        break
      is_prime[q] = 0
  return is_prime,P

N = int(input())
is_prime,P = Eratosthenes(300000)
P = deque(P)
d = defaultdict(int)
Q = []
ans = 0
m = 0
while len(P):
  c = P.popleft()
  if c > N:
    break
  for p in 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)
0