結果

問題 No.1897 Sum of 2nd Max
ユーザー lloyz
提出日時 2022-04-08 23:36:42
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 645 ms / 2,000 ms
コード長 347 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 82,500 KB
実行使用メモリ 69,000 KB
最終ジャッジ日時 2024-11-28 14:51:12
合計ジャッジ時間 9,444 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
mod = 998244353

def calc(x):
    num = pow(k, n, mod)
    num -= pow(x - 1, n, mod)
    num %= mod
    num -= ((k - x + 1) * n % mod) * pow(x - 1, n - 1, mod) % mod
    num %= mod
    return num

ans = 0
for i in range(1, k + 1):
    num = calc(i) - calc(i + 1)
    ans += i * num % mod
    ans %= mod
print(ans)
0