結果
問題 | No.732 3PrimeCounting |
ユーザー | convexineq |
提出日時 | 2021-03-17 17:14:45 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 636 ms / 3,000 ms |
コード長 | 1,981 bytes |
コンパイル時間 | 683 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 109,532 KB |
最終ジャッジ日時 | 2024-11-15 08:52:02 |
合計ジャッジ時間 | 16,823 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
52,864 KB |
testcase_01 | AC | 39 ms
52,736 KB |
testcase_02 | AC | 39 ms
52,992 KB |
testcase_03 | AC | 39 ms
52,608 KB |
testcase_04 | AC | 40 ms
52,736 KB |
testcase_05 | AC | 39 ms
52,736 KB |
testcase_06 | AC | 39 ms
52,736 KB |
testcase_07 | AC | 41 ms
52,480 KB |
testcase_08 | AC | 40 ms
52,736 KB |
testcase_09 | AC | 43 ms
58,624 KB |
testcase_10 | AC | 44 ms
59,136 KB |
testcase_11 | AC | 43 ms
58,368 KB |
testcase_12 | AC | 42 ms
58,368 KB |
testcase_13 | AC | 43 ms
58,624 KB |
testcase_14 | AC | 44 ms
59,008 KB |
testcase_15 | AC | 42 ms
58,624 KB |
testcase_16 | AC | 43 ms
58,496 KB |
testcase_17 | AC | 42 ms
58,752 KB |
testcase_18 | AC | 45 ms
59,392 KB |
testcase_19 | AC | 45 ms
59,520 KB |
testcase_20 | AC | 75 ms
73,984 KB |
testcase_21 | AC | 86 ms
76,544 KB |
testcase_22 | AC | 91 ms
76,448 KB |
testcase_23 | AC | 68 ms
70,784 KB |
testcase_24 | AC | 68 ms
71,424 KB |
testcase_25 | AC | 93 ms
76,800 KB |
testcase_26 | AC | 97 ms
76,672 KB |
testcase_27 | AC | 81 ms
76,416 KB |
testcase_28 | AC | 79 ms
76,544 KB |
testcase_29 | AC | 84 ms
76,416 KB |
testcase_30 | AC | 82 ms
76,416 KB |
testcase_31 | AC | 88 ms
76,532 KB |
testcase_32 | AC | 91 ms
76,672 KB |
testcase_33 | AC | 93 ms
76,928 KB |
testcase_34 | AC | 96 ms
77,056 KB |
testcase_35 | AC | 95 ms
77,056 KB |
testcase_36 | AC | 97 ms
76,800 KB |
testcase_37 | AC | 79 ms
73,088 KB |
testcase_38 | AC | 78 ms
73,472 KB |
testcase_39 | AC | 98 ms
77,056 KB |
testcase_40 | AC | 90 ms
76,672 KB |
testcase_41 | AC | 86 ms
76,528 KB |
testcase_42 | AC | 85 ms
76,672 KB |
testcase_43 | AC | 85 ms
76,288 KB |
testcase_44 | AC | 84 ms
76,544 KB |
testcase_45 | AC | 84 ms
76,400 KB |
testcase_46 | AC | 86 ms
76,288 KB |
testcase_47 | AC | 89 ms
76,408 KB |
testcase_48 | AC | 99 ms
77,072 KB |
testcase_49 | AC | 94 ms
77,056 KB |
testcase_50 | AC | 84 ms
76,544 KB |
testcase_51 | AC | 85 ms
76,672 KB |
testcase_52 | AC | 79 ms
76,656 KB |
testcase_53 | AC | 114 ms
79,104 KB |
testcase_54 | AC | 356 ms
93,012 KB |
testcase_55 | AC | 350 ms
93,136 KB |
testcase_56 | AC | 348 ms
93,144 KB |
testcase_57 | AC | 155 ms
81,536 KB |
testcase_58 | AC | 164 ms
81,536 KB |
testcase_59 | AC | 117 ms
79,232 KB |
testcase_60 | AC | 210 ms
84,956 KB |
testcase_61 | AC | 208 ms
84,700 KB |
testcase_62 | AC | 354 ms
93,576 KB |
testcase_63 | AC | 239 ms
87,448 KB |
testcase_64 | AC | 209 ms
84,708 KB |
testcase_65 | AC | 212 ms
85,100 KB |
testcase_66 | AC | 66 ms
69,504 KB |
testcase_67 | AC | 66 ms
69,760 KB |
testcase_68 | AC | 354 ms
93,024 KB |
testcase_69 | AC | 351 ms
93,284 KB |
testcase_70 | AC | 354 ms
93,032 KB |
testcase_71 | AC | 350 ms
92,772 KB |
testcase_72 | AC | 240 ms
87,292 KB |
testcase_73 | AC | 418 ms
98,004 KB |
testcase_74 | AC | 421 ms
98,008 KB |
testcase_75 | AC | 99 ms
76,928 KB |
testcase_76 | AC | 352 ms
93,116 KB |
testcase_77 | AC | 161 ms
81,408 KB |
testcase_78 | AC | 415 ms
96,444 KB |
testcase_79 | AC | 353 ms
93,424 KB |
testcase_80 | AC | 414 ms
95,716 KB |
testcase_81 | AC | 348 ms
93,044 KB |
testcase_82 | AC | 81 ms
76,660 KB |
testcase_83 | AC | 158 ms
81,536 KB |
testcase_84 | AC | 211 ms
84,736 KB |
testcase_85 | AC | 344 ms
93,148 KB |
testcase_86 | AC | 413 ms
96,152 KB |
testcase_87 | AC | 635 ms
109,532 KB |
testcase_88 | AC | 636 ms
109,412 KB |
ソースコード
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)