結果

問題 No.2487 Multiple of M
ユーザー Carpenters-CatCarpenters-Cat
提出日時 2023-09-29 22:48:59
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,347 bytes
コンパイル時間 393 ms
コンパイル使用メモリ 10,812 KB
実行使用メモリ 8,528 KB
最終ジャッジ日時 2023-09-30 12:52:01
合計ジャッジ時間 2,863 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,260 KB
testcase_01 AC 17 ms
8,376 KB
testcase_02 AC 17 ms
8,160 KB
testcase_03 WA -
testcase_04 AC 16 ms
8,528 KB
testcase_05 AC 17 ms
8,096 KB
testcase_06 AC 17 ms
8,168 KB
testcase_07 AC 17 ms
8,528 KB
testcase_08 AC 17 ms
8,500 KB
testcase_09 AC 18 ms
8,092 KB
testcase_10 AC 16 ms
8,456 KB
testcase_11 AC 17 ms
8,152 KB
testcase_12 AC 17 ms
8,136 KB
testcase_13 AC 17 ms
8,128 KB
testcase_14 AC 17 ms
8,080 KB
testcase_15 AC 17 ms
8,124 KB
testcase_16 AC 17 ms
8,124 KB
testcase_17 AC 17 ms
8,116 KB
testcase_18 AC 17 ms
8,148 KB
testcase_19 AC 17 ms
8,152 KB
testcase_20 AC 18 ms
8,120 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 17 ms
8,192 KB
testcase_32 AC 17 ms
8,076 KB
testcase_33 AC 17 ms
8,160 KB
testcase_34 AC 17 ms
8,144 KB
testcase_35 AC 18 ms
8,084 KB
testcase_36 AC 17 ms
8,156 KB
testcase_37 AC 17 ms
8,088 KB
testcase_38 WA -
testcase_39 AC 17 ms
8,092 KB
testcase_40 AC 17 ms
8,160 KB
testcase_41 AC 17 ms
8,256 KB
testcase_42 AC 17 ms
8,156 KB
testcase_43 AC 17 ms
8,152 KB
testcase_44 AC 17 ms
8,160 KB
testcase_45 AC 17 ms
8,096 KB
testcase_46 AC 17 ms
8,164 KB
testcase_47 AC 17 ms
8,124 KB
testcase_48 AC 17 ms
8,188 KB
testcase_49 AC 17 ms
8,116 KB
testcase_50 WA -
testcase_51 AC 17 ms
8,160 KB
testcase_52 AC 17 ms
8,156 KB
testcase_53 AC 17 ms
8,192 KB
testcase_54 WA -
testcase_55 AC 17 ms
8,120 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
N, M, K = map(int, input().split())
mod = 998244353
g = gcd(M, K)
if N == 1 :
    print(0)
    exit()
if (M - 1) % mod == 0 :
    ans = 0
    if N & 1 :
        ans = 1
    else :
        ans = mod - 1
    ans = (ans * (g - 1)) % mod
    print(ans)
else :
    X = pow(M - 1, N - 1, mod)
    iv = pow(M - 1, -1, mod)
    n = N - 2
    mat = [[mod - iv, (g * iv) % mod], [0, 1]]
    ret = [[1, 0], [0, 1]]
    while n > 0 :
        if n & 1 :
            ret2 = [[0, 0], [0, 0]]
            for i in range(2) :
                for j in range(2) :
                    for k in range(2) :
                        ret2[i][j] += ret[i][k] * mat[k][j]
                        ret2[i][j] %= mod
            for i in range(2) :
                for j in range(2) :
                    ret[i][j] = ret2[i][j]
        n >>= 1
        ret2 = [[0, 0], [0, 0]]
        for i in range(2) :
            for j in range(2) :
                for k in range(2) :
                    ret2[i][j] += mat[i][k] * mat[k][j]
                    ret2[i][j] %= mod
        for i in range(2) :
            for j in range(2) :
                mat[i][j] = ret2[i][j]
    b = (g - 1) * iv
    b %= mod
    bn = b * ret[0][0] + ret[0][1]
    bn %= mod
    bn = (bn * pow(M - 1, N - 1, mod)) % mod
    # print(bn)
    # print(X)
    print((X + mod - bn) % mod)
0