結果

問題 No.732 3PrimeCounting
ユーザー togetogehattogetogehat
提出日時 2018-10-02 08:20:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,741 ms / 3,000 ms
コード長 369 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 45,476 KB
最終ジャッジ日時 2024-04-20 14:28:23
合計ジャッジ時間 62,094 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 497 ms
44,200 KB
testcase_01 AC 495 ms
44,196 KB
testcase_02 AC 488 ms
44,452 KB
testcase_03 AC 494 ms
44,068 KB
testcase_04 AC 495 ms
44,328 KB
testcase_05 AC 498 ms
44,452 KB
testcase_06 AC 494 ms
44,172 KB
testcase_07 AC 495 ms
44,328 KB
testcase_08 AC 492 ms
44,088 KB
testcase_09 AC 499 ms
44,196 KB
testcase_10 AC 492 ms
44,200 KB
testcase_11 AC 504 ms
44,324 KB
testcase_12 AC 489 ms
44,332 KB
testcase_13 AC 493 ms
44,456 KB
testcase_14 AC 492 ms
44,072 KB
testcase_15 AC 496 ms
44,204 KB
testcase_16 AC 501 ms
44,452 KB
testcase_17 AC 494 ms
44,316 KB
testcase_18 AC 496 ms
44,320 KB
testcase_19 AC 500 ms
44,076 KB
testcase_20 AC 533 ms
44,324 KB
testcase_21 AC 549 ms
44,072 KB
testcase_22 AC 502 ms
44,580 KB
testcase_23 AC 525 ms
44,464 KB
testcase_24 AC 529 ms
44,072 KB
testcase_25 AC 529 ms
44,108 KB
testcase_26 AC 536 ms
44,328 KB
testcase_27 AC 529 ms
44,196 KB
testcase_28 AC 525 ms
44,204 KB
testcase_29 AC 520 ms
44,204 KB
testcase_30 AC 513 ms
44,452 KB
testcase_31 AC 512 ms
44,588 KB
testcase_32 AC 521 ms
44,204 KB
testcase_33 AC 505 ms
44,196 KB
testcase_34 AC 502 ms
44,072 KB
testcase_35 AC 503 ms
44,328 KB
testcase_36 AC 497 ms
44,464 KB
testcase_37 AC 486 ms
44,456 KB
testcase_38 AC 492 ms
44,336 KB
testcase_39 AC 496 ms
44,196 KB
testcase_40 AC 494 ms
44,320 KB
testcase_41 AC 499 ms
44,452 KB
testcase_42 AC 500 ms
44,200 KB
testcase_43 AC 491 ms
44,068 KB
testcase_44 AC 491 ms
44,332 KB
testcase_45 AC 510 ms
44,068 KB
testcase_46 AC 517 ms
44,320 KB
testcase_47 AC 491 ms
44,232 KB
testcase_48 AC 499 ms
44,452 KB
testcase_49 AC 503 ms
44,068 KB
testcase_50 AC 495 ms
44,328 KB
testcase_51 AC 492 ms
44,324 KB
testcase_52 AC 493 ms
44,456 KB
testcase_53 AC 509 ms
44,068 KB
testcase_54 AC 990 ms
44,072 KB
testcase_55 AC 1,011 ms
44,320 KB
testcase_56 AC 978 ms
44,320 KB
testcase_57 AC 565 ms
44,064 KB
testcase_58 AC 559 ms
44,332 KB
testcase_59 AC 517 ms
44,200 KB
testcase_60 AC 605 ms
44,076 KB
testcase_61 AC 614 ms
44,072 KB
testcase_62 AC 1,013 ms
44,712 KB
testcase_63 AC 754 ms
44,324 KB
testcase_64 AC 687 ms
44,452 KB
testcase_65 AC 671 ms
44,548 KB
testcase_66 AC 491 ms
44,196 KB
testcase_67 AC 494 ms
44,272 KB
testcase_68 AC 1,094 ms
44,484 KB
testcase_69 AC 1,081 ms
44,196 KB
testcase_70 AC 994 ms
44,204 KB
testcase_71 AC 1,021 ms
44,072 KB
testcase_72 AC 744 ms
44,072 KB
testcase_73 AC 1,355 ms
45,088 KB
testcase_74 AC 1,395 ms
45,476 KB
testcase_75 AC 512 ms
44,332 KB
testcase_76 AC 1,091 ms
44,064 KB
testcase_77 AC 578 ms
44,328 KB
testcase_78 AC 1,172 ms
45,224 KB
testcase_79 AC 1,101 ms
44,068 KB
testcase_80 AC 1,073 ms
45,032 KB
testcase_81 AC 1,009 ms
44,316 KB
testcase_82 AC 494 ms
44,328 KB
testcase_83 AC 574 ms
44,324 KB
testcase_84 AC 583 ms
44,064 KB
testcase_85 AC 969 ms
44,204 KB
testcase_86 AC 1,126 ms
45,096 KB
testcase_87 AC 1,719 ms
45,220 KB
testcase_88 AC 1,741 ms
45,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
n = int(input())
sieve = np.ones(n*3+1, dtype=bool)
for i in range(2, int((n*3)**0.5)+2):
    if sieve[i]:
        sieve[i+i::i] = False
ps1 = np.where(sieve)[0][2:]
ps2 = ps1[ps1 <= n]
cnt = np.zeros(n*3+1, dtype='int64')
res = 0
for i in reversed(range(len(ps2))):
    a = ps2[i]
    res += cnt[ps1 - a].sum()
    cnt[ps2[i+1:] + a] += 1
print(res)
0