結果
問題 | No.2903 A Round-the-World Trip with the Tent |
ユーザー | 👑 獅子座じゃない人 |
提出日時 | 2024-09-15 00:43:48 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 105 ms / 2,000 ms |
コード長 | 1,775 bytes |
コンパイル時間 | 266 ms |
コンパイル使用メモリ | 82,956 KB |
実行使用メモリ | 93,792 KB |
最終ジャッジ日時 | 2024-09-27 19:30:36 |
合計ジャッジ時間 | 3,657 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 34 ms
52,892 KB |
testcase_01 | AC | 35 ms
54,356 KB |
testcase_02 | AC | 105 ms
93,792 KB |
testcase_03 | AC | 34 ms
53,236 KB |
testcase_04 | AC | 97 ms
93,588 KB |
testcase_05 | AC | 45 ms
63,080 KB |
testcase_06 | AC | 60 ms
78,968 KB |
testcase_07 | AC | 63 ms
79,016 KB |
testcase_08 | AC | 95 ms
93,060 KB |
testcase_09 | AC | 94 ms
91,920 KB |
testcase_10 | AC | 61 ms
79,600 KB |
testcase_11 | AC | 95 ms
92,448 KB |
testcase_12 | AC | 73 ms
84,884 KB |
testcase_13 | AC | 61 ms
79,484 KB |
testcase_14 | AC | 81 ms
87,288 KB |
testcase_15 | AC | 82 ms
87,260 KB |
testcase_16 | AC | 66 ms
81,252 KB |
testcase_17 | AC | 52 ms
72,400 KB |
testcase_18 | AC | 52 ms
72,184 KB |
testcase_19 | AC | 47 ms
66,412 KB |
testcase_20 | AC | 98 ms
93,116 KB |
testcase_21 | AC | 96 ms
93,464 KB |
testcase_22 | AC | 64 ms
80,152 KB |
testcase_23 | AC | 88 ms
88,800 KB |
testcase_24 | AC | 86 ms
87,172 KB |
testcase_25 | AC | 39 ms
52,560 KB |
testcase_26 | AC | 36 ms
53,064 KB |
testcase_27 | AC | 36 ms
54,152 KB |
testcase_28 | AC | 35 ms
53,068 KB |
testcase_29 | AC | 34 ms
52,748 KB |
testcase_30 | AC | 33 ms
53,960 KB |
testcase_31 | AC | 36 ms
53,876 KB |
testcase_32 | AC | 35 ms
52,832 KB |
testcase_33 | AC | 34 ms
53,468 KB |
testcase_34 | AC | 33 ms
53,284 KB |
testcase_35 | AC | 34 ms
53,844 KB |
testcase_36 | AC | 35 ms
52,824 KB |
testcase_37 | AC | 38 ms
53,440 KB |
testcase_38 | AC | 36 ms
52,204 KB |
testcase_39 | AC | 36 ms
52,400 KB |
testcase_40 | AC | 35 ms
54,004 KB |
testcase_41 | AC | 36 ms
52,932 KB |
testcase_42 | AC | 34 ms
53,912 KB |
testcase_43 | AC | 36 ms
52,900 KB |
testcase_44 | AC | 35 ms
52,724 KB |
ソースコード
#using ChatGPT o1-preview mod = 998244353 def linear_sieve(N): mu = [1] * (N + 1) spf = [0] * (N + 1) # 最小素因数 primes = [] for i in range(2, N + 1): if spf[i] == 0: spf[i] = i mu[i] = -1 primes.append(i) for p in primes: if p * i > N: break spf[p * i] = p if i % p == 0: mu[p * i] = 0 break else: mu[p * i] = -mu[i] return mu, spf def factorize(n, spf): factors = {} while n > 1: p = spf[n] factors[p] = factors.get(p, 0) + 1 n //= p return factors def generate_divisors(factors): from itertools import product exponents_list = [] for p, exp in factors.items(): exponents_list.append([p ** e for e in range(exp + 1)]) divisors = set() for exponents in product(*exponents_list): prod = 1 for e in exponents: prod *= e divisors.add(prod) return list(divisors) def main(): def solve(): K_str, N_str = input().split() K = int(K_str) N = int(N_str) mod = 998244353 if N == 1: if K == 1: print(2) else: print(3) return mu, spf = linear_sieve(N) factors = factorize(N, spf) divisors = generate_divisors(factors) total = 0 for d in divisors: nd = N // d mu_nd = mu[nd] if mu_nd == 0: continue pow2d = pow(2, d, mod) total = (total + mu_nd * pow2d) % mod total = (total + mod) % mod # 負の値を回避 print(total) solve() main()