結果

問題 No.1552 Simple Dice Game
コンテスト
ユーザー ygd.
提出日時 2021-06-18 21:52:37
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 707 ms / 2,500 ms
コード長 633 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 196 ms
コンパイル使用メモリ 85,564 KB
実行使用メモリ 117,468 KB
最終ジャッジ日時 2026-03-07 02:30:31
合計ジャッジ時間 7,821 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def main():
    mod = 998244353
    N,M = map(int,input().split())
    mx = 0
    pown = [0]
    for i in range(1,M+1):
        temp = pow(i,N-1,mod)
        pown.append(temp)


    for i in range(1,M+1): #1-M
        #temp = (i*(i+1)//2)*pow(i,N-1,mod)*N - ((i-1)*i//2)*pow(i-1,N-1,mod)*N
        temp = (i*(i+1)//2)*pown[i]*N - ((i-1)*i//2)*pown[i-1]*N
        mx += temp*i
        mx %= mod
    mn = 0
    for i in range(1,M+1):
        temp = ((M+i)*(M-i+1)//2)*pown[M-i+1]*N - ((M+i+1)*(M-i)//2)*pown[M-i]*N
        mn += temp*i
        mn %= mod
    
    ans = mx - mn
    print(ans%mod)


if __name__ == '__main__':
    main()
0