結果

問題 No.2141 Enumeratest
ユーザー hikariri
提出日時 2023-03-23 18:45:56
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 206 ms / 2,000 ms
コード長 1,628 bytes
コンパイル時間 3,855 ms
コンパイル使用メモリ 231,084 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-18 15:32:59
合計ジャッジ時間 6,113 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
typedef modint998244353 mint;
#endif
typedef long long  ll;
typedef pair<int,int> pii; typedef pair<ll,ll> pll;
const int INF = 1e9; const long long LINF = 1e18;
const int MOD = 998244353; const int MOD1 = 1e9+7;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(x) x.begin(), x.end()
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
void yorn(bool ans){cout << (ans?"Yes":"No") << endl; return;}

ll power(ll a, ll b, ll m){
    ll ans = 1, p = a;
    rep(i,50){
        ll wari = (1LL<<i);
        if((b/wari)%2==1) ans = ans*p%m;
        p = p*p%m;
    }
    return ans;
}

// しばらくはsize_tをキャストに任せてみようかな
int main(){
    ll n,m; cin >> n >> m;
    ll a = m/n;
    ll b = m%n; // a+1個
    ll c = n-b; // a個
    ll ans = 1;
    ll mm = m;
    // mmCa+1
    rep(k,b){
        rep(j,a+1){
            ans = ans*mm%MOD;
            mm--;
        }
        ll bumbo = 1;
        for(int i=1;i<=a+1;i++){
            bumbo = bumbo*i%MOD;
        }
        ans = ans*power(bumbo,MOD-2,MOD)%MOD;
    }
    if(a!=0){
        rep(i,c){
            rep(j,a){
                ans = ans*mm%MOD;
                mm--;
            }
            ll bumbo = 1;
            for(int k=1;k<=a;k++){
                bumbo = bumbo*k%MOD;
            }
            ans = ans*power(bumbo,MOD-2,MOD)%MOD;
        }
    }
    cout << ans << endl;

}
0