結果
問題 | No.2045 Two Reflections |
ユーザー | neterukun |
提出日時 | 2022-08-19 22:18:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 76 ms / 2,000 ms |
コード長 | 1,804 bytes |
コンパイル時間 | 389 ms |
コンパイル使用メモリ | 82,396 KB |
実行使用メモリ | 92,080 KB |
最終ジャッジ日時 | 2024-10-08 09:10:36 |
合計ジャッジ時間 | 3,033 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 37 ms
52,396 KB |
testcase_01 | AC | 37 ms
54,056 KB |
testcase_02 | AC | 66 ms
83,508 KB |
testcase_03 | AC | 68 ms
81,332 KB |
testcase_04 | AC | 72 ms
86,508 KB |
testcase_05 | AC | 35 ms
52,820 KB |
testcase_06 | AC | 36 ms
53,644 KB |
testcase_07 | AC | 67 ms
83,972 KB |
testcase_08 | AC | 76 ms
86,000 KB |
testcase_09 | AC | 36 ms
53,900 KB |
testcase_10 | AC | 35 ms
52,912 KB |
testcase_11 | AC | 51 ms
69,416 KB |
testcase_12 | AC | 35 ms
53,232 KB |
testcase_13 | AC | 35 ms
53,120 KB |
testcase_14 | AC | 37 ms
52,448 KB |
testcase_15 | AC | 37 ms
54,480 KB |
testcase_16 | AC | 36 ms
52,740 KB |
testcase_17 | AC | 34 ms
53,220 KB |
testcase_18 | AC | 35 ms
52,572 KB |
testcase_19 | AC | 35 ms
52,456 KB |
testcase_20 | AC | 70 ms
92,080 KB |
testcase_21 | AC | 68 ms
84,140 KB |
testcase_22 | AC | 68 ms
84,428 KB |
testcase_23 | AC | 66 ms
83,964 KB |
testcase_24 | AC | 67 ms
84,960 KB |
testcase_25 | AC | 67 ms
83,384 KB |
testcase_26 | AC | 64 ms
84,848 KB |
testcase_27 | AC | 64 ms
83,952 KB |
testcase_28 | AC | 64 ms
83,188 KB |
testcase_29 | AC | 65 ms
83,920 KB |
ソースコード
def gcd(a, b): while b: a, b = b, a % b return a def lcm(a, b): return (a * b) // gcd(a, b) def all_gcd(array): n = len(array) ans = array[0] for i in range(1, n): ans = gcd(ans, array[i]) return ans def all_lcm_int(array): ans = array[0] for i in range(1, len(array)): ans = (ans * array[i]) // gcd(ans, array[i]) return ans def all_lcm_dict(array): primes = {} for num in array: for k in range(2, int(num ** 0.5) + 1): cnt = 0 while num % k == 0: cnt += 1 num //= k if cnt != 0: if k not in primes: primes[k] = cnt else: primes[k] = max(cnt, primes[k]) if num != 1: if num not in primes: primes[num] = 1 return primes n, p, q = map(int, input().split()) MOD = 998244353 if n == 1: print(1) exit() if p + q <= n: if p == 1 and q == 1: print(1) elif p == 1: print(2) elif q == 1: print(2) else: print(4) exit() if p == 1: print(2) exit() if q == 1: print(2) exit() a = [i for i in range(n)] b = [i for i in range(n)] b[0:p] = b[0:p][::-1] b[n - q:n] = b[n - q:n][::-1] nxt_pos = {} for i in range(n): nxt_pos[b[i]] = i visited = [False] * n ans = 2 ptns = [] for i in range(n): if visited[i]: continue visited[i] = True ptn = 1 while True: nxt_i = nxt_pos[i] if visited[nxt_i]: break visited[nxt_i] = True i = nxt_i ptn += 1 ptns.append(ptn) lcms = all_lcm_dict(ptns) for p in lcms: cnt = lcms[p] ans *= pow(p, cnt, MOD) ans %= MOD print(ans)