結果

問題 No.2351 Butterfly in Summer
ユーザー 👑 timitimi
提出日時 2023-06-16 21:25:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 469 bytes
コンパイル時間 396 ms
コンパイル使用メモリ 86,916 KB
実行使用メモリ 76,032 KB
最終ジャッジ日時 2023-09-06 18:32:54
合計ジャッジ時間 3,220 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,328 KB
testcase_01 AC 70 ms
71,228 KB
testcase_02 AC 71 ms
71,224 KB
testcase_03 AC 76 ms
75,896 KB
testcase_04 AC 70 ms
71,116 KB
testcase_05 AC 76 ms
75,944 KB
testcase_06 AC 77 ms
75,972 KB
testcase_07 AC 77 ms
75,640 KB
testcase_08 AC 76 ms
75,856 KB
testcase_09 AC 73 ms
75,880 KB
testcase_10 AC 75 ms
75,668 KB
testcase_11 AC 74 ms
75,732 KB
testcase_12 AC 75 ms
75,948 KB
testcase_13 AC 75 ms
75,828 KB
testcase_14 AC 73 ms
75,740 KB
testcase_15 AC 73 ms
75,748 KB
testcase_16 AC 72 ms
75,840 KB
testcase_17 AC 72 ms
76,032 KB
testcase_18 AC 74 ms
75,772 KB
testcase_19 AC 74 ms
75,800 KB
testcase_20 AC 72 ms
75,824 KB
testcase_21 AC 73 ms
76,032 KB
testcase_22 AC 71 ms
71,532 KB
testcase_23 AC 73 ms
76,028 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K=map(int, input().split())
mod=998244353
ans=K*(K-1)*N%mod

def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m
gt=modinv(K,mod)

for i in range(N):
  ans*=gt 
  ans%=mod 
print(ans)
0