結果

問題 No.1552 Simple Dice Game
ユーザー rianoriano
提出日時 2021-06-18 21:45:19
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 962 ms / 2,500 ms
コード長 1,047 bytes
コンパイル時間 1,621 ms
コンパイル使用メモリ 165,220 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-09-04 22:40:55
合計ジャッジ時間 13,394 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 816 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 1 ms
4,384 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 710 ms
4,380 KB
testcase_10 AC 808 ms
4,380 KB
testcase_11 AC 840 ms
4,380 KB
testcase_12 AC 247 ms
4,380 KB
testcase_13 AC 695 ms
4,380 KB
testcase_14 AC 417 ms
4,380 KB
testcase_15 AC 500 ms
4,380 KB
testcase_16 AC 71 ms
4,384 KB
testcase_17 AC 121 ms
4,384 KB
testcase_18 AC 657 ms
4,384 KB
testcase_19 AC 943 ms
4,380 KB
testcase_20 AC 954 ms
4,380 KB
testcase_21 AC 951 ms
4,380 KB
testcase_22 AC 942 ms
4,388 KB
testcase_23 AC 962 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Pr pair<ll,ll>
#define Tp tuple<ll,ll,ll>
using Graph = vector<vector<int>>;

ll mod = 998244353;


//累乗 aのb乗、正しmを法として求める
long long pw(long long a,long long b,long long m){
    if(b==0) return 1;
    else if(b%2==0){
        long long x = pw(a,b/2,m);
        return (x*x)%m;
    }
    else{
        long long x = pw(a,b-1,m);
        return (a*x)%m;
    }
}



//mod逆元
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}



int main() {
    ll N,M; cin >> N >> M;
    ll cnt = pw(M,N,mod)*(M-1)%mod;
    rep(i,M-1){
        ll k = i+1;
        cnt += 2*mod - 2*pw(k,N,mod);
        cnt %= mod;
    }
    ll ans = (cnt * (N%mod)) %mod * (1+M) %mod * modinv(2LL,mod) % mod;
    cout <<ans << endl;
}
0