結果

問題 No.2045 Two Reflections
ユーザー neterukunneterukun
提出日時 2022-08-19 22:14:55
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,696 bytes
コンパイル時間 348 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 91,520 KB
最終ジャッジ日時 2024-04-17 00:56:06
合計ジャッジ時間 3,120 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,480 KB
testcase_01 AC 40 ms
52,480 KB
testcase_02 AC 69 ms
82,816 KB
testcase_03 AC 70 ms
80,640 KB
testcase_04 AC 81 ms
85,632 KB
testcase_05 AC 42 ms
52,096 KB
testcase_06 AC 42 ms
52,480 KB
testcase_07 AC 85 ms
84,096 KB
testcase_08 AC 83 ms
85,632 KB
testcase_09 AC 42 ms
52,224 KB
testcase_10 AC 42 ms
52,224 KB
testcase_11 AC 66 ms
68,480 KB
testcase_12 WA -
testcase_13 AC 42 ms
52,352 KB
testcase_14 AC 42 ms
52,352 KB
testcase_15 AC 42 ms
52,096 KB
testcase_16 AC 42 ms
52,224 KB
testcase_17 AC 42 ms
52,352 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 85 ms
91,520 KB
testcase_21 AC 75 ms
83,200 KB
testcase_22 AC 74 ms
83,840 KB
testcase_23 AC 74 ms
83,584 KB
testcase_24 AC 76 ms
83,328 KB
testcase_25 AC 75 ms
83,328 KB
testcase_26 AC 70 ms
82,816 KB
testcase_27 AC 71 ms
82,560 KB
testcase_28 AC 71 ms
82,816 KB
testcase_29 AC 69 ms
82,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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 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()


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)
0