結果
問題 | No.732 3PrimeCounting |
ユーザー | onakasuitacity |
提出日時 | 2020-10-17 14:52:46 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 817 ms / 3,000 ms |
コード長 | 1,770 bytes |
コンパイル時間 | 246 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 272,428 KB |
最終ジャッジ日時 | 2024-07-21 02:29:53 |
合計ジャッジ時間 | 17,871 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
52,096 KB |
testcase_01 | AC | 37 ms
52,864 KB |
testcase_02 | AC | 38 ms
52,864 KB |
testcase_03 | AC | 36 ms
52,608 KB |
testcase_04 | AC | 38 ms
52,480 KB |
testcase_05 | AC | 41 ms
52,608 KB |
testcase_06 | AC | 48 ms
60,800 KB |
testcase_07 | AC | 47 ms
60,928 KB |
testcase_08 | AC | 46 ms
61,056 KB |
testcase_09 | AC | 51 ms
60,928 KB |
testcase_10 | AC | 53 ms
60,928 KB |
testcase_11 | AC | 51 ms
60,416 KB |
testcase_12 | AC | 53 ms
60,672 KB |
testcase_13 | AC | 53 ms
60,416 KB |
testcase_14 | AC | 51 ms
60,544 KB |
testcase_15 | AC | 51 ms
60,416 KB |
testcase_16 | AC | 53 ms
60,416 KB |
testcase_17 | AC | 48 ms
60,928 KB |
testcase_18 | AC | 47 ms
61,056 KB |
testcase_19 | AC | 46 ms
60,928 KB |
testcase_20 | AC | 59 ms
68,736 KB |
testcase_21 | AC | 76 ms
76,032 KB |
testcase_22 | AC | 76 ms
76,160 KB |
testcase_23 | AC | 57 ms
65,280 KB |
testcase_24 | AC | 56 ms
65,280 KB |
testcase_25 | AC | 97 ms
77,568 KB |
testcase_26 | AC | 97 ms
77,824 KB |
testcase_27 | AC | 71 ms
73,600 KB |
testcase_28 | AC | 73 ms
74,112 KB |
testcase_29 | AC | 74 ms
75,904 KB |
testcase_30 | AC | 73 ms
75,904 KB |
testcase_31 | AC | 76 ms
76,160 KB |
testcase_32 | AC | 83 ms
77,952 KB |
testcase_33 | AC | 91 ms
77,952 KB |
testcase_34 | AC | 87 ms
77,696 KB |
testcase_35 | AC | 82 ms
77,440 KB |
testcase_36 | AC | 82 ms
77,440 KB |
testcase_37 | AC | 54 ms
66,688 KB |
testcase_38 | AC | 56 ms
66,688 KB |
testcase_39 | AC | 86 ms
77,952 KB |
testcase_40 | AC | 79 ms
76,032 KB |
testcase_41 | AC | 74 ms
76,160 KB |
testcase_42 | AC | 75 ms
76,416 KB |
testcase_43 | AC | 75 ms
76,416 KB |
testcase_44 | AC | 74 ms
76,416 KB |
testcase_45 | AC | 72 ms
76,032 KB |
testcase_46 | AC | 78 ms
75,776 KB |
testcase_47 | AC | 82 ms
76,288 KB |
testcase_48 | AC | 96 ms
78,080 KB |
testcase_49 | AC | 96 ms
78,336 KB |
testcase_50 | AC | 80 ms
76,160 KB |
testcase_51 | AC | 74 ms
76,544 KB |
testcase_52 | AC | 65 ms
73,856 KB |
testcase_53 | AC | 122 ms
96,256 KB |
testcase_54 | AC | 430 ms
186,312 KB |
testcase_55 | AC | 432 ms
186,696 KB |
testcase_56 | AC | 434 ms
182,596 KB |
testcase_57 | AC | 176 ms
106,624 KB |
testcase_58 | AC | 175 ms
106,880 KB |
testcase_59 | AC | 121 ms
96,256 KB |
testcase_60 | AC | 238 ms
126,976 KB |
testcase_61 | AC | 237 ms
127,104 KB |
testcase_62 | AC | 430 ms
180,332 KB |
testcase_63 | AC | 271 ms
135,040 KB |
testcase_64 | AC | 239 ms
127,104 KB |
testcase_65 | AC | 243 ms
127,360 KB |
testcase_66 | AC | 51 ms
63,744 KB |
testcase_67 | AC | 52 ms
63,744 KB |
testcase_68 | AC | 438 ms
182,444 KB |
testcase_69 | AC | 439 ms
182,408 KB |
testcase_70 | AC | 433 ms
182,384 KB |
testcase_71 | AC | 436 ms
182,252 KB |
testcase_72 | AC | 284 ms
135,168 KB |
testcase_73 | AC | 514 ms
199,232 KB |
testcase_74 | AC | 508 ms
199,236 KB |
testcase_75 | AC | 86 ms
77,696 KB |
testcase_76 | AC | 435 ms
183,832 KB |
testcase_77 | AC | 166 ms
105,600 KB |
testcase_78 | AC | 512 ms
200,740 KB |
testcase_79 | AC | 440 ms
182,400 KB |
testcase_80 | AC | 510 ms
204,320 KB |
testcase_81 | AC | 426 ms
183,392 KB |
testcase_82 | AC | 64 ms
73,600 KB |
testcase_83 | AC | 168 ms
105,984 KB |
testcase_84 | AC | 239 ms
129,920 KB |
testcase_85 | AC | 434 ms
187,960 KB |
testcase_86 | AC | 509 ms
204,524 KB |
testcase_87 | AC | 804 ms
271,788 KB |
testcase_88 | AC | 817 ms
272,428 KB |
ソースコード
import sys INF = 1 << 60 MOD = 998244353 sys.setrecursionlimit(2147483647) input = lambda:sys.stdin.readline().rstrip() prime = 998244353 root = 3 def _fmt(A, inverse = False): N = len(A) logN = (N - 1).bit_length() base = pow(root, (prime - 1) // N * (1 - 2 * inverse) % (prime - 1), prime) step = N for k in range(logN): step >>= 1 w = pow(base, step, prime) wj = 1 nA = [0] * N for j in range(1 << k): for i in range(1 << logN - k - 1): s, t = i + j * step, i + j * step + (N >> 1) ps, pt = i + j * step * 2, i + j * step * 2 + step nA[s], nA[t] = (A[ps] + A[pt] * wj) % prime, (A[ps] - A[pt] * wj) % prime wj = (wj * w) % prime A = nA return A def convolution(f, g): N = 1 << (len(f) + len(g) - 2).bit_length() Ff, Fg = _fmt(f + [0] * (N - len(f))), _fmt(g + [0] * (N - len(g))) N_inv = pow(N, prime - 2, prime) fg = _fmt([a * b % prime * N_inv % prime for a, b in zip(Ff, Fg)], inverse = True) del fg[len(f) + len(g) - 1:] return fg def resolve(): n = int(input()) N = 3 * n primes = [] sieve = list(range(N + 1)) for i in range(2, N + 1): if sieve[i] == i: primes.append(i) for p in primes: if sieve[i] < p or i * p > N: break sieve[i * p] = p f = [0] * (n + 1) g = [0] * (2 * n + 1) for p in primes: if p <= n: f[p] += 1 g[p * 2] += 1 a = 0 f3 = convolution(f, convolution(f, f)) for p in primes: a += f3[p] b = 0 fg = convolution(f, g) for p in primes: b += fg[p] ans = (a - 3 * b) // 6 print(ans) resolve()