結果

問題 No.732 3PrimeCounting
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-17 23:21:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,078 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 12,056 KB
実行使用メモリ 202,956 KB
最終ジャッジ日時 2023-10-21 07:34:35
合計ジャッジ時間 211,456 ms
ジャッジサーバーID
(参考情報)
judge14 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 AC 2,191 ms
99,836 KB
testcase_02 AC 2,285 ms
99,852 KB
testcase_03 AC 2,274 ms
99,852 KB
testcase_04 AC 2,256 ms
99,852 KB
testcase_05 AC 2,260 ms
99,852 KB
testcase_06 AC 2,247 ms
99,856 KB
testcase_07 AC 2,257 ms
99,856 KB
testcase_08 AC 2,220 ms
99,852 KB
testcase_09 AC 2,270 ms
99,852 KB
testcase_10 AC 2,301 ms
99,836 KB
testcase_11 AC 2,236 ms
99,836 KB
testcase_12 AC 2,281 ms
99,860 KB
testcase_13 AC 2,238 ms
99,860 KB
testcase_14 AC 2,263 ms
99,840 KB
testcase_15 AC 2,262 ms
99,856 KB
testcase_16 AC 2,284 ms
99,856 KB
testcase_17 AC 2,238 ms
99,856 KB
testcase_18 AC 2,244 ms
99,856 KB
testcase_19 AC 2,248 ms
99,856 KB
testcase_20 AC 2,218 ms
99,852 KB
testcase_21 AC 2,223 ms
99,844 KB
testcase_22 AC 2,253 ms
99,844 KB
testcase_23 AC 2,204 ms
99,860 KB
testcase_24 AC 2,192 ms
99,860 KB
testcase_25 AC 2,258 ms
99,844 KB
testcase_26 AC 2,222 ms
99,828 KB
testcase_27 AC 2,217 ms
99,848 KB
testcase_28 AC 2,237 ms
99,848 KB
testcase_29 AC 2,210 ms
99,828 KB
testcase_30 AC 2,221 ms
99,844 KB
testcase_31 AC 2,239 ms
99,828 KB
testcase_32 AC 2,230 ms
99,844 KB
testcase_33 AC 2,269 ms
99,844 KB
testcase_34 AC 2,250 ms
99,844 KB
testcase_35 AC 2,265 ms
99,844 KB
testcase_36 AC 2,231 ms
99,844 KB
testcase_37 AC 2,252 ms
99,856 KB
testcase_38 AC 2,200 ms
99,856 KB
testcase_39 AC 2,224 ms
99,844 KB
testcase_40 AC 2,237 ms
99,844 KB
testcase_41 AC 2,196 ms
99,828 KB
testcase_42 AC 2,238 ms
99,828 KB
testcase_43 AC 2,196 ms
99,844 KB
testcase_44 AC 2,231 ms
99,844 KB
testcase_45 AC 2,239 ms
99,848 KB
testcase_46 AC 2,316 ms
99,848 KB
testcase_47 AC 2,224 ms
99,848 KB
testcase_48 AC 2,250 ms
99,828 KB
testcase_49 AC 2,219 ms
99,828 KB
testcase_50 AC 2,237 ms
99,844 KB
testcase_51 AC 2,239 ms
99,844 KB
testcase_52 AC 2,223 ms
99,844 KB
testcase_53 AC 2,256 ms
99,828 KB
testcase_54 AC 2,378 ms
118,412 KB
testcase_55 AC 2,317 ms
118,412 KB
testcase_56 AC 2,273 ms
118,412 KB
testcase_57 AC 2,201 ms
100,412 KB
testcase_58 AC 2,221 ms
100,396 KB
testcase_59 AC 2,266 ms
99,844 KB
testcase_60 AC 2,263 ms
102,664 KB
testcase_61 AC 2,229 ms
102,648 KB
testcase_62 AC 2,287 ms
118,380 KB
testcase_63 AC 2,281 ms
105,072 KB
testcase_64 AC 2,262 ms
103,688 KB
testcase_65 AC 2,275 ms
103,688 KB
testcase_66 AC 2,243 ms
99,856 KB
testcase_67 AC 2,250 ms
99,856 KB
testcase_68 AC 2,289 ms
118,396 KB
testcase_69 AC 2,283 ms
118,412 KB
testcase_70 AC 2,355 ms
118,396 KB
testcase_71 AC 2,307 ms
118,396 KB
testcase_72 AC 2,228 ms
104,824 KB
testcase_73 AC 2,336 ms
118,644 KB
testcase_74 AC 2,371 ms
118,628 KB
testcase_75 AC 2,175 ms
99,844 KB
testcase_76 AC 2,346 ms
118,396 KB
testcase_77 AC 2,282 ms
100,412 KB
testcase_78 AC 2,333 ms
118,228 KB
testcase_79 AC 2,322 ms
118,412 KB
testcase_80 AC 2,337 ms
118,416 KB
testcase_81 AC 2,320 ms
118,412 KB
testcase_82 AC 2,249 ms
99,848 KB
testcase_83 AC 2,261 ms
100,412 KB
testcase_84 AC 2,256 ms
102,664 KB
testcase_85 AC 2,312 ms
116,340 KB
testcase_86 AC 2,354 ms
118,444 KB
testcase_87 AC 2,405 ms
141,716 KB
testcase_88 AC 2,407 ms
202,956 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())
primes = np.array(list(prime_set(N)), dtype=np.int32)
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
p = np.array(list(prime_set(len(cnt))), dtype=np.int32)
print(cnt[p].sum())
0