結果

問題 No.732 3PrimeCounting
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-17 23:26:39
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 2,426 ms / 3,000 ms
コード長 1,070 bytes
コンパイル時間 133 ms
コンパイル使用メモリ 11,972 KB
実行使用メモリ 208,900 KB
最終ジャッジ日時 2023-10-21 07:38:20
合計ジャッジ時間 156,944 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,288 ms
105,556 KB
testcase_01 AC 2,253 ms
105,556 KB
testcase_02 AC 2,244 ms
105,540 KB
testcase_03 AC 2,256 ms
105,556 KB
testcase_04 AC 2,254 ms
105,556 KB
testcase_05 AC 2,221 ms
105,556 KB
testcase_06 AC 2,231 ms
105,556 KB
testcase_07 AC 2,265 ms
105,556 KB
testcase_08 AC 2,258 ms
105,556 KB
testcase_09 AC 2,246 ms
105,556 KB
testcase_10 AC 2,286 ms
105,556 KB
testcase_11 AC 2,256 ms
105,540 KB
testcase_12 AC 2,244 ms
105,556 KB
testcase_13 AC 2,271 ms
105,556 KB
testcase_14 AC 2,308 ms
105,556 KB
testcase_15 AC 2,311 ms
105,556 KB
testcase_16 AC 2,240 ms
105,556 KB
testcase_17 AC 2,320 ms
105,556 KB
testcase_18 AC 2,271 ms
105,556 KB
testcase_19 AC 2,279 ms
105,556 KB
testcase_20 AC 2,283 ms
105,556 KB
testcase_21 AC 2,293 ms
105,556 KB
testcase_22 AC 2,282 ms
105,556 KB
testcase_23 AC 2,290 ms
105,556 KB
testcase_24 AC 2,272 ms
105,540 KB
testcase_25 AC 2,271 ms
105,556 KB
testcase_26 AC 2,267 ms
105,556 KB
testcase_27 AC 2,244 ms
105,556 KB
testcase_28 AC 2,231 ms
105,556 KB
testcase_29 AC 2,240 ms
105,540 KB
testcase_30 AC 2,315 ms
105,556 KB
testcase_31 AC 2,266 ms
105,556 KB
testcase_32 AC 2,272 ms
105,540 KB
testcase_33 AC 2,276 ms
105,556 KB
testcase_34 AC 2,269 ms
105,540 KB
testcase_35 AC 2,214 ms
105,556 KB
testcase_36 AC 2,271 ms
105,540 KB
testcase_37 AC 2,268 ms
105,556 KB
testcase_38 AC 2,288 ms
105,540 KB
testcase_39 AC 2,281 ms
105,556 KB
testcase_40 AC 2,307 ms
105,540 KB
testcase_41 AC 2,230 ms
105,556 KB
testcase_42 AC 2,230 ms
105,556 KB
testcase_43 AC 2,250 ms
105,556 KB
testcase_44 AC 2,291 ms
105,556 KB
testcase_45 AC 2,280 ms
105,556 KB
testcase_46 AC 2,318 ms
105,556 KB
testcase_47 AC 2,284 ms
105,556 KB
testcase_48 AC 2,246 ms
105,540 KB
testcase_49 AC 2,286 ms
105,556 KB
testcase_50 AC 2,261 ms
105,556 KB
testcase_51 AC 2,288 ms
105,556 KB
testcase_52 AC 2,271 ms
105,556 KB
testcase_53 AC 2,274 ms
105,556 KB
testcase_54 AC 2,379 ms
118,724 KB
testcase_55 AC 2,334 ms
118,724 KB
testcase_56 AC 2,377 ms
119,732 KB
testcase_57 AC 2,283 ms
105,556 KB
testcase_58 AC 2,289 ms
105,556 KB
testcase_59 AC 2,289 ms
105,556 KB
testcase_60 AC 2,324 ms
105,556 KB
testcase_61 AC 2,295 ms
105,556 KB
testcase_62 AC 2,373 ms
118,692 KB
testcase_63 AC 2,314 ms
106,884 KB
testcase_64 AC 2,285 ms
105,616 KB
testcase_65 AC 2,338 ms
105,616 KB
testcase_66 AC 2,314 ms
105,616 KB
testcase_67 AC 2,312 ms
105,616 KB
testcase_68 AC 2,357 ms
119,792 KB
testcase_69 AC 2,395 ms
119,792 KB
testcase_70 AC 2,399 ms
119,792 KB
testcase_71 AC 2,388 ms
118,784 KB
testcase_72 AC 2,330 ms
106,944 KB
testcase_73 AC 2,330 ms
120,928 KB
testcase_74 AC 2,343 ms
121,936 KB
testcase_75 AC 2,292 ms
105,616 KB
testcase_76 AC 2,334 ms
119,792 KB
testcase_77 AC 2,268 ms
105,616 KB
testcase_78 AC 2,343 ms
119,752 KB
testcase_79 AC 2,309 ms
119,792 KB
testcase_80 AC 2,340 ms
118,756 KB
testcase_81 AC 2,356 ms
119,792 KB
testcase_82 AC 2,337 ms
105,616 KB
testcase_83 AC 2,303 ms
105,616 KB
testcase_84 AC 2,289 ms
105,600 KB
testcase_85 AC 2,368 ms
117,720 KB
testcase_86 AC 2,373 ms
119,756 KB
testcase_87 AC 2,418 ms
142,336 KB
testcase_88 AC 2,426 ms
208,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from itertools import chain
from scipy.signal import fftconvolve
import numpy as np


def convolve(A, B):
    sz = len(A) + len(B)
    fft_len = 1 << (sz-1).bit_length()
    F1 = np.fft.rfft(A, fft_len)
    F2 = np.fft.rfft(B, fft_len)
    G = F1 * F2
    res = np.fft.irfft(G, fft_len)
    return np.rint(res + 0.001).astype(np.int64)[:sz - 1]


def prime_set(N):
    """
    Nまでの素数のsetを返す
    """
    if N < 4:
        return ({}, {}, {2}, {2, 3})[N]
    Nsq = int(N ** 0.5 + 0.5) + 1
    primes = {2, 3} | set(chain(range(5, N + 1, 6), range(7, N + 1, 6)))
    for i in range(5, Nsq, 2):
        if i in primes:
            primes -= set(range(i * i, N + 1, i * 2))
    return primes


N = int(input())
U = 100000
P = np.array(list(prime_set(3 * U + 1)), dtype=np.int32)

primes = P[P <= N]
F = np.bincount(1 * primes).astype(np.int64)
G = np.bincount(2 * primes).astype(np.int64)
H = np.bincount(3 * primes).astype(np.int64)

FFF = convolve(F, convolve(F, F))
FG = convolve(F, G)

cnt = (FFF - 3 * FG + 2 * H) // 6
print(cnt[P[P < len(cnt)]].sum())
0