結果

問題 No.3394 Big Binom
コンテスト
ユーザー Mike scarf
提出日時 2025-12-12 15:35:09
言語 C++23
(gcc 13.3.0 + boost 1.89.0)
結果
TLE  
実行時間 -
コード長 1,109 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,899 ms
コンパイル使用メモリ 276,524 KB
実行使用メモリ 43,300 KB
最終ジャッジ日時 2025-12-12 15:35:20
合計ジャッジ時間 10,288 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 2 TLE * 2 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll maxn=2000005;
const ll mod=998244353;
ll s[maxn+5],p[maxn+5];
ll qmksm(ll a,ll b){
    ll ans,cur,i,j,k;
    ans=1,cur=a;
    while(b){
        if(b&1)ans=ans*cur%mod;
        cur=cur*cur%mod;
        b>>=1;
    }
    return ans;
}
ll ny(ll a){
    return qmksm(a,mod-2);
}
void init(){
    ll i,j,k;
    s[0]=1;
    for(i=1;i<=maxn;i++)s[i]=s[i-1]*i%mod;
    p[maxn]=ny(s[maxn]);
    for(i=maxn-1;i>=0;i--)p[i]=p[i+1]*(i+1)%mod;
}
ll cal(ll n,ll m){
    ll i,j,k,ans,cur;
    if(m<0 or m>n)return 0;
    if(m==0 or m==n)return 1;
    if(n<=maxn)return s[n]*p[m]%mod*p[n-m]%mod;
    if(m>n/2)m=n-m;
    cur=1;
    for(i=0;i<m;i++)cur=cur*(n-i)%mod;
    if(m<=maxn)ans=p[m];
    else{
        ans=1;
        for(i=1;i<=m;i++)ans=ans*i%mod;
        ans=ny(ans);
    }
    return cur*ans%mod;
}
ll luc(ll n,ll m){
    ll i,j,k;
    if(m==0)return 1;
    return luc(n/mod,m/mod)*cal(n%mod,m%mod)%mod;
}
int main(){
    ll n,m,i,j,k;
    init();
    while(~scanf("%lld%lld",&n,&m)){
        printf("%lld\n",luc(n,m));
    }
    return 0;
}
0