結果

問題 No.3394 Big Binom
コンテスト
ユーザー vjudge1
提出日時 2025-12-02 02:27:35
言語 C++14
(gcc 13.3.0 + boost 1.89.0)
結果
TLE  
実行時間 -
コード長 809 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,421 ms
コンパイル使用メモリ 162,956 KB
実行使用メモリ 16,076 KB
最終ジャッジ日時 2025-12-02 02:27:41
合計ジャッジ時間 5,684 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 2 TLE * 1 -- * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll M = 998244353;
ll fpow(ll x, ll n){
    ll ret = 1;
    while(n){
        if(n % 2) ret = ret * x % M;
        x = x * x % M;
        n >>= 1;
    }
    return ret;
}
ll fac(ll n){
    ll ret = 1;
    if(n < M / 2){
        for(int i = 2; i <= n; i++) ret = ret * i % M;
    }else{
        for(int i = n + 1; i < M; i++) ret = ret * i % M;
        ret = (M - 1) * fpow(ret, M - 2) % M;
    }
    return ret;
}
ll C(ll n, ll m){
    if(m == 0) return 1;
    if(n < m) return 0;
    if(n - m < m) m = n - m;
    if(n >= M) return C(n / M, m / M) * C(n % M, m % M) % M;
    return fac(n) * fpow(fac(m), M - 2) % M * fpow(fac(n - m), M - 2) % M;
}

int main(){
    ll n, k;
    cin >> n >> k;
    cout << C(n, k) << endl;
    return 0;
}
0