結果

問題 No.2351 Butterfly in Summer
ユーザー HIcoderHIcoder
提出日時 2023-07-06 17:53:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 2,000 ms
コード長 1,435 bytes
コンパイル時間 798 ms
コンパイル使用メモリ 101,040 KB
実行使用メモリ 6,264 KB
最終ジャッジ日時 2023-09-27 18:46:28
合計ジャッジ時間 2,607 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
6,088 KB
testcase_01 AC 5 ms
6,208 KB
testcase_02 AC 5 ms
6,144 KB
testcase_03 AC 5 ms
6,144 KB
testcase_04 AC 6 ms
6,100 KB
testcase_05 AC 5 ms
6,100 KB
testcase_06 AC 5 ms
5,968 KB
testcase_07 AC 5 ms
5,968 KB
testcase_08 AC 5 ms
6,140 KB
testcase_09 AC 5 ms
6,048 KB
testcase_10 AC 5 ms
6,212 KB
testcase_11 AC 4 ms
5,992 KB
testcase_12 AC 5 ms
6,264 KB
testcase_13 AC 5 ms
6,140 KB
testcase_14 AC 6 ms
6,144 KB
testcase_15 AC 5 ms
6,204 KB
testcase_16 AC 5 ms
6,140 KB
testcase_17 AC 5 ms
5,992 KB
testcase_18 AC 6 ms
5,984 KB
testcase_19 AC 6 ms
5,968 KB
testcase_20 AC 5 ms
6,076 KB
testcase_21 AC 6 ms
6,008 KB
testcase_22 AC 6 ms
6,016 KB
testcase_23 AC 5 ms
5,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const double PI=acos(-1);



//xのy乗
ll mod_pow(ll x,ll y,ll mod){
    ll power=x;
    ll ret = 1;
    while(y>0){
        if(y&1){
           ret = ret*power%mod;
        }
        power = power*power%mod;
        y = y>>1;
    }
    return ret;

}



struct combination{
    typedef long long ll;
    std::vector<ll> fact,ifact;
    combination(ll n): fact(n+1),ifact(n+1){
        fact[0]=1;//0!=1通り
        for(ll i=1;i<=n;i++) fact[i] = fact[i-1]*i%MOD;
        //ifact[n] = fact[n].inv();
        
        // n!の逆元がifact[n]
        ifact[n] = mod_pow(fact[n],MOD-2,MOD);// n!を(mod-2)乗した後でmodであまりをとった
        for(ll i=n;i>=1;i--) ifact[i-1] = ifact[i]*i%MOD;
    }

    ll operator()(ll n,ll k){
        if(k<0 || k>n) return 0;
        // n!/( k!*(n-k)! )
        return (fact[n]*ifact[k])%MOD * ifact[n-k]%MOD;
    }

};


combination comb(2*100000);

int main(){
    int N,K;
    cin>>N>>K;


    ll c=mod_pow(K,N,MOD);
    ll inv=mod_pow(c,MOD-2,MOD);

    ll nom=K;
    nom*=(K-1);
    nom%=MOD;
    nom*=comb(N,N-1);
    nom%=MOD;

    ll ans=nom*inv%MOD;
    cout<<ans<<endl;


}
0