結果

問題 No.732 3PrimeCounting
ユーザー PNJPNJ
提出日時 2023-11-21 05:19:20
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 649 bytes
コンパイル時間 423 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 112,812 KB
最終ジャッジ日時 2023-11-21 05:20:09
合計ジャッジ時間 48,378 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
69,508 KB
testcase_01 AC 61 ms
69,508 KB
testcase_02 AC 59 ms
69,504 KB
testcase_03 AC 63 ms
69,504 KB
testcase_04 AC 60 ms
69,504 KB
testcase_05 AC 58 ms
69,504 KB
testcase_06 AC 58 ms
69,504 KB
testcase_07 AC 58 ms
69,508 KB
testcase_08 AC 58 ms
69,504 KB
testcase_09 AC 58 ms
69,504 KB
testcase_10 AC 59 ms
69,504 KB
testcase_11 AC 60 ms
69,504 KB
testcase_12 AC 59 ms
69,504 KB
testcase_13 AC 59 ms
69,504 KB
testcase_14 AC 59 ms
69,504 KB
testcase_15 AC 59 ms
69,508 KB
testcase_16 AC 59 ms
69,508 KB
testcase_17 AC 60 ms
69,504 KB
testcase_18 AC 61 ms
69,504 KB
testcase_19 AC 58 ms
69,508 KB
testcase_20 AC 66 ms
73,996 KB
testcase_21 AC 73 ms
76,064 KB
testcase_22 AC 74 ms
76,064 KB
testcase_23 AC 61 ms
71,896 KB
testcase_24 AC 62 ms
71,896 KB
testcase_25 AC 89 ms
80,032 KB
testcase_26 AC 77 ms
76,192 KB
testcase_27 AC 68 ms
73,996 KB
testcase_28 AC 67 ms
73,996 KB
testcase_29 AC 73 ms
76,064 KB
testcase_30 AC 73 ms
76,064 KB
testcase_31 AC 79 ms
76,064 KB
testcase_32 AC 84 ms
76,704 KB
testcase_33 AC 80 ms
76,832 KB
testcase_34 AC 80 ms
76,832 KB
testcase_35 AC 75 ms
76,064 KB
testcase_36 AC 75 ms
76,064 KB
testcase_37 AC 64 ms
73,996 KB
testcase_38 AC 65 ms
73,996 KB
testcase_39 AC 76 ms
76,064 KB
testcase_40 AC 77 ms
76,064 KB
testcase_41 AC 76 ms
76,064 KB
testcase_42 AC 75 ms
76,064 KB
testcase_43 AC 74 ms
76,064 KB
testcase_44 AC 79 ms
76,064 KB
testcase_45 AC 69 ms
73,996 KB
testcase_46 AC 68 ms
73,996 KB
testcase_47 AC 71 ms
73,996 KB
testcase_48 AC 93 ms
80,032 KB
testcase_49 AC 93 ms
80,032 KB
testcase_50 AC 75 ms
76,064 KB
testcase_51 AC 77 ms
76,064 KB
testcase_52 AC 68 ms
73,996 KB
testcase_53 AC 127 ms
80,032 KB
testcase_54 AC 1,311 ms
89,004 KB
testcase_55 AC 1,301 ms
89,004 KB
testcase_56 AC 1,295 ms
89,004 KB
testcase_57 AC 304 ms
80,032 KB
testcase_58 AC 261 ms
80,032 KB
testcase_59 AC 133 ms
80,032 KB
testcase_60 AC 378 ms
80,032 KB
testcase_61 AC 410 ms
80,032 KB
testcase_62 AC 1,717 ms
92,076 KB
testcase_63 AC 756 ms
82,604 KB
testcase_64 AC 482 ms
80,300 KB
testcase_65 AC 481 ms
80,300 KB
testcase_66 AC 61 ms
69,504 KB
testcase_67 AC 59 ms
69,504 KB
testcase_68 AC 1,490 ms
91,564 KB
testcase_69 AC 1,488 ms
91,564 KB
testcase_70 AC 1,322 ms
89,004 KB
testcase_71 AC 1,321 ms
89,004 KB
testcase_72 AC 692 ms
82,604 KB
testcase_73 AC 2,810 ms
102,956 KB
testcase_74 AC 2,791 ms
102,956 KB
testcase_75 AC 91 ms
77,728 KB
testcase_76 AC 1,445 ms
89,516 KB
testcase_77 AC 284 ms
80,032 KB
testcase_78 AC 2,154 ms
96,172 KB
testcase_79 AC 1,509 ms
91,564 KB
testcase_80 AC 1,908 ms
95,020 KB
testcase_81 AC 1,337 ms
89,004 KB
testcase_82 AC 65 ms
73,996 KB
testcase_83 AC 275 ms
80,032 KB
testcase_84 AC 300 ms
80,032 KB
testcase_85 AC 1,112 ms
86,828 KB
testcase_86 AC 1,975 ms
95,532 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 P

N = int(input())
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