結果

問題 No.732 3PrimeCounting
ユーザー rlangevinrlangevin
提出日時 2023-07-28 12:30:35
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 716 ms / 3,000 ms
コード長 948 bytes
コンパイル時間 98 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 86,928 KB
最終ジャッジ日時 2024-04-15 21:16:00
合計ジャッジ時間 49,644 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 492 ms
44,256 KB
testcase_01 AC 492 ms
44,512 KB
testcase_02 AC 494 ms
44,508 KB
testcase_03 AC 494 ms
44,508 KB
testcase_04 AC 495 ms
44,376 KB
testcase_05 AC 499 ms
44,776 KB
testcase_06 AC 494 ms
44,120 KB
testcase_07 AC 497 ms
44,512 KB
testcase_08 AC 503 ms
44,136 KB
testcase_09 AC 501 ms
44,132 KB
testcase_10 AC 496 ms
44,380 KB
testcase_11 AC 493 ms
44,176 KB
testcase_12 AC 485 ms
44,380 KB
testcase_13 AC 496 ms
44,008 KB
testcase_14 AC 496 ms
44,764 KB
testcase_15 AC 490 ms
44,640 KB
testcase_16 AC 514 ms
44,128 KB
testcase_17 AC 491 ms
44,384 KB
testcase_18 AC 496 ms
44,260 KB
testcase_19 AC 496 ms
44,392 KB
testcase_20 AC 495 ms
44,384 KB
testcase_21 AC 500 ms
44,508 KB
testcase_22 AC 504 ms
44,516 KB
testcase_23 AC 495 ms
44,512 KB
testcase_24 AC 488 ms
44,388 KB
testcase_25 AC 491 ms
44,516 KB
testcase_26 AC 490 ms
44,644 KB
testcase_27 AC 486 ms
44,516 KB
testcase_28 AC 485 ms
44,508 KB
testcase_29 AC 481 ms
44,004 KB
testcase_30 AC 489 ms
44,132 KB
testcase_31 AC 491 ms
44,136 KB
testcase_32 AC 490 ms
44,384 KB
testcase_33 AC 486 ms
44,128 KB
testcase_34 AC 492 ms
44,508 KB
testcase_35 AC 487 ms
44,520 KB
testcase_36 AC 560 ms
44,420 KB
testcase_37 AC 494 ms
44,392 KB
testcase_38 AC 486 ms
44,256 KB
testcase_39 AC 480 ms
44,380 KB
testcase_40 AC 488 ms
44,252 KB
testcase_41 AC 482 ms
44,644 KB
testcase_42 AC 494 ms
44,516 KB
testcase_43 AC 485 ms
44,388 KB
testcase_44 AC 492 ms
44,132 KB
testcase_45 AC 479 ms
44,380 KB
testcase_46 AC 476 ms
44,376 KB
testcase_47 AC 481 ms
44,008 KB
testcase_48 AC 491 ms
44,132 KB
testcase_49 AC 486 ms
44,128 KB
testcase_50 AC 495 ms
44,508 KB
testcase_51 AC 487 ms
44,388 KB
testcase_52 AC 494 ms
44,512 KB
testcase_53 AC 499 ms
46,728 KB
testcase_54 AC 587 ms
65,828 KB
testcase_55 AC 591 ms
65,328 KB
testcase_56 AC 595 ms
65,572 KB
testcase_57 AC 519 ms
52,296 KB
testcase_58 AC 517 ms
52,436 KB
testcase_59 AC 502 ms
47,040 KB
testcase_60 AC 521 ms
53,700 KB
testcase_61 AC 541 ms
53,336 KB
testcase_62 AC 591 ms
65,944 KB
testcase_63 AC 562 ms
61,984 KB
testcase_64 AC 542 ms
53,572 KB
testcase_65 AC 534 ms
53,704 KB
testcase_66 AC 491 ms
44,516 KB
testcase_67 AC 487 ms
44,128 KB
testcase_68 AC 589 ms
65,480 KB
testcase_69 AC 595 ms
65,356 KB
testcase_70 AC 586 ms
65,336 KB
testcase_71 AC 577 ms
65,484 KB
testcase_72 AC 547 ms
61,128 KB
testcase_73 AC 663 ms
81,832 KB
testcase_74 AC 659 ms
82,092 KB
testcase_75 AC 498 ms
44,520 KB
testcase_76 AC 594 ms
65,328 KB
testcase_77 AC 514 ms
52,680 KB
testcase_78 AC 654 ms
81,260 KB
testcase_79 AC 589 ms
65,564 KB
testcase_80 AC 646 ms
81,072 KB
testcase_81 AC 585 ms
65,772 KB
testcase_82 AC 486 ms
44,504 KB
testcase_83 AC 521 ms
52,552 KB
testcase_84 AC 519 ms
53,448 KB
testcase_85 AC 592 ms
64,088 KB
testcase_86 AC 629 ms
81,620 KB
testcase_87 AC 698 ms
86,788 KB
testcase_88 AC 716 ms
86,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import numpy as np
from math import sqrt, ceil

def Sieve(n):
    lst = [True] * (n + 1)
    S = set()
    for i in range(2, ceil(sqrt(n)) + 1):
        if lst[i]:
            for j in range(2 * i, n + 1, i):
                lst[j] = False

    for i in range(3):
        lst[i] = False
    return lst

def convolve(f, g):
    fft_len = 1
    while 2 * fft_len < len(f) + len(g) - 1:
        fft_len *= 2
    fft_len *= 2
    Ff = np.fft.rfft(f, fft_len)
    Fg = np.fft.rfft(g, fft_len)
    Fh = Ff * Fg
    h = np.fft.irfft(Fh, fft_len)
    h = np.rint(h).astype(np.int64)

    return h[:len(f) + len(g) - 1]


N = int(input())
L = Sieve(3 * N + 5)
f = np.zeros(N + 1)
f2 = np.zeros(3 * N)
for i in range(3, N + 1):
    if L[i]:
        f[i] = 1
    if L[i]:
        f2[2 * i] = 1

g = convolve(convolve(f, f), f)
h = convolve(f2, f)[:len(g)]

ans = g - 3 * h
cnt = 0
for i in range(3, len(ans)):
    if L[i]:
        cnt += ans[i]

print(cnt//6)
0