結果

問題 No.732 3PrimeCounting
ユーザー convexineqconvexineq
提出日時 2021-03-17 17:14:45
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 637 ms / 3,000 ms
コード長 1,981 bytes
コンパイル時間 234 ms
コンパイル使用メモリ 82,416 KB
実行使用メモリ 110,104 KB
最終ジャッジ日時 2024-04-27 08:10:43
合計ジャッジ時間 16,556 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
55,036 KB
testcase_01 AC 39 ms
54,444 KB
testcase_02 AC 39 ms
53,944 KB
testcase_03 AC 39 ms
53,392 KB
testcase_04 AC 40 ms
53,824 KB
testcase_05 AC 40 ms
53,496 KB
testcase_06 AC 40 ms
53,864 KB
testcase_07 AC 40 ms
53,792 KB
testcase_08 AC 41 ms
53,188 KB
testcase_09 AC 43 ms
59,200 KB
testcase_10 AC 45 ms
59,924 KB
testcase_11 AC 44 ms
60,232 KB
testcase_12 AC 43 ms
59,112 KB
testcase_13 AC 43 ms
59,124 KB
testcase_14 AC 44 ms
61,244 KB
testcase_15 AC 43 ms
60,064 KB
testcase_16 AC 43 ms
59,676 KB
testcase_17 AC 44 ms
59,568 KB
testcase_18 AC 45 ms
60,980 KB
testcase_19 AC 46 ms
60,408 KB
testcase_20 AC 74 ms
74,564 KB
testcase_21 AC 85 ms
76,812 KB
testcase_22 AC 85 ms
76,592 KB
testcase_23 AC 69 ms
72,692 KB
testcase_24 AC 69 ms
72,936 KB
testcase_25 AC 95 ms
77,072 KB
testcase_26 AC 92 ms
77,128 KB
testcase_27 AC 81 ms
76,700 KB
testcase_28 AC 81 ms
76,700 KB
testcase_29 AC 84 ms
76,860 KB
testcase_30 AC 83 ms
76,868 KB
testcase_31 AC 85 ms
76,724 KB
testcase_32 AC 93 ms
77,380 KB
testcase_33 AC 93 ms
77,124 KB
testcase_34 AC 92 ms
77,144 KB
testcase_35 AC 91 ms
76,992 KB
testcase_36 AC 91 ms
76,992 KB
testcase_37 AC 71 ms
73,684 KB
testcase_38 AC 73 ms
74,216 KB
testcase_39 AC 91 ms
76,924 KB
testcase_40 AC 86 ms
76,768 KB
testcase_41 AC 84 ms
76,868 KB
testcase_42 AC 89 ms
76,916 KB
testcase_43 AC 84 ms
76,784 KB
testcase_44 AC 84 ms
77,004 KB
testcase_45 AC 80 ms
76,676 KB
testcase_46 AC 79 ms
76,632 KB
testcase_47 AC 83 ms
76,696 KB
testcase_48 AC 95 ms
77,316 KB
testcase_49 AC 94 ms
77,452 KB
testcase_50 AC 85 ms
76,460 KB
testcase_51 AC 85 ms
76,728 KB
testcase_52 AC 79 ms
77,044 KB
testcase_53 AC 115 ms
79,160 KB
testcase_54 AC 353 ms
93,396 KB
testcase_55 AC 354 ms
93,272 KB
testcase_56 AC 348 ms
93,528 KB
testcase_57 AC 156 ms
81,968 KB
testcase_58 AC 156 ms
81,836 KB
testcase_59 AC 116 ms
79,512 KB
testcase_60 AC 208 ms
84,832 KB
testcase_61 AC 208 ms
84,956 KB
testcase_62 AC 350 ms
93,664 KB
testcase_63 AC 239 ms
87,236 KB
testcase_64 AC 211 ms
84,972 KB
testcase_65 AC 211 ms
84,964 KB
testcase_66 AC 64 ms
70,752 KB
testcase_67 AC 66 ms
70,716 KB
testcase_68 AC 351 ms
93,956 KB
testcase_69 AC 351 ms
93,540 KB
testcase_70 AC 350 ms
93,288 KB
testcase_71 AC 349 ms
93,156 KB
testcase_72 AC 241 ms
87,544 KB
testcase_73 AC 418 ms
98,460 KB
testcase_74 AC 415 ms
98,480 KB
testcase_75 AC 95 ms
77,248 KB
testcase_76 AC 426 ms
93,248 KB
testcase_77 AC 155 ms
81,604 KB
testcase_78 AC 417 ms
96,836 KB
testcase_79 AC 355 ms
93,300 KB
testcase_80 AC 411 ms
96,240 KB
testcase_81 AC 352 ms
93,040 KB
testcase_82 AC 79 ms
76,768 KB
testcase_83 AC 155 ms
81,840 KB
testcase_84 AC 208 ms
84,864 KB
testcase_85 AC 348 ms
93,400 KB
testcase_86 AC 413 ms
96,692 KB
testcase_87 AC 633 ms
109,868 KB
testcase_88 AC 637 ms
110,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

ROOT = 3
MOD = 998244353
roots  = [pow(ROOT,(MOD-1)>>i,MOD) for i in range(24)] # 1 の 2^i 乗根
iroots = [pow(x,MOD-2,MOD) for x in roots] # 1 の 2^i 乗根の逆元

def untt(a,n):
    for i in range(n):
        m = 1<<(n-i-1)
        for s in range(1<<i):
            w_N = 1
            s *= m*2
            for p in range(m):
                a[s+p], a[s+p+m] = (a[s+p]+a[s+p+m])%MOD, (a[s+p]-a[s+p+m])*w_N%MOD
                w_N = w_N*roots[n-i]%MOD

def iuntt(a,n):
    for i in range(n):
        m = 1<<i
        for s in range(1<<(n-i-1)):
            w_N = 1
            s *= m*2
            for p in range(m):
                a[s+p], a[s+p+m] = (a[s+p]+a[s+p+m]*w_N)%MOD, (a[s+p]-a[s+p+m]*w_N)%MOD
                w_N = w_N*iroots[i+1]%MOD
            
    inv = pow((MOD+1)//2,n,MOD)
    for i in range(1<<n):
        a[i] = a[i]*inv%MOD

def convolution(a,b):
    la = len(a)
    lb = len(b)
    if min(la, lb) <= 50:
        if la < lb:
            la,lb = lb,la
            a,b = b,a
        res = [0]*(la+lb-1)
        for i in range(la):
            for j in range(lb):
                res[i+j] += a[i]*b[j]
                res[i+j] %= MOD
        return res

    deg = la+lb-2
    n = deg.bit_length()
    N = 1<<n
    a += [0]*(N-len(a))
    b += [0]*(N-len(b))
    untt(a,n)
    untt(b,n)
    for i in range(N):
      a[i] = a[i]*b[i]%MOD
    iuntt(a,n)
    return a[:deg+1]

def Eratosthenes(N): #N以下の素数のリストを返す
    N+=1
    is_prime_list = [True]*N
    m = int(N**0.5)+1
    for i in range(3,m,2):
        if is_prime_list[i]:
            is_prime_list[i*i::2*i]=[False]*((N-i*i-1)//(2*i)+1)
    return [2] + [i for i in range(3,N,2) if is_prime_list[i]]

n = int(input())
r = [0]*(n+1)
s = [0]*(2*n+1)
for p in Eratosthenes(n):
    r[p] += 1
    s[2*p] += 1
r[2] = s[4] = 0

a = convolution(convolution(r[:],r[:]),r[:])
b = convolution(r[:],s[:])

x = y = 0
for p in Eratosthenes(3*n):
    x += a[p]
    y += b[p]

print((x-3*y)//6)
0