結果

問題 No.2045 Two Reflections
ユーザー Kude
提出日時 2022-08-19 22:27:05
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 661 bytes
コンパイル時間 219 ms
コンパイル使用メモリ 82,460 KB
実行使用メモリ 64,876 KB
最終ジャッジ日時 2024-10-08 09:25:22
合計ジャッジ時間 2,604 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
def lcm(a, b):
    return a // gcd(a, b) * b
def solve():
    n, p, q = map(int, input().split())
    if n == 1:
        return 1
    if p == 1 or q == 1:
        return 2 if p != 1 or q != 1 else 1
    if p == q == n:
        return 2
    if p + q <= n:
        return 4
    a = list(range(n))
    a[:p] = a[p-1::-1]
    a[-q:] = a[:-q-1:-1]
    visited = [False] * n
    ans = 1
    for i in range(n):
        if visited[i]:
            continue
        cnt = 0
        while not visited[i]:
            visited[i] = True
            cnt += 1
            i = a[i]
        ans = lcm(ans, cnt)
    return ans * 2

print(solve() % 998244353)
0