結果

問題 No.2613 Sum of Combination
ユーザー 蜜蜂蜜蜂
提出日時 2024-01-06 12:25:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,579 bytes
コンパイル時間 3,965 ms
コンパイル使用メモリ 229,292 KB
実行使用メモリ 122,956 KB
最終ジャッジ日時 2024-01-19 20:50:51
合計ジャッジ時間 19,978 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 274 ms
122,956 KB
testcase_01 AC 276 ms
122,956 KB
testcase_02 WA -
testcase_03 AC 275 ms
122,956 KB
testcase_04 AC 276 ms
122,956 KB
testcase_05 AC 276 ms
122,956 KB
testcase_06 AC 276 ms
122,956 KB
testcase_07 AC 275 ms
122,956 KB
testcase_08 AC 277 ms
122,956 KB
testcase_09 AC 277 ms
122,956 KB
testcase_10 AC 282 ms
122,956 KB
testcase_11 AC 278 ms
122,956 KB
testcase_12 AC 276 ms
122,956 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

// g++-13 12.cpp -std=c++17 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/all>
using namespace atcoder;

using ll = long long;
using ld = long double;
 
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;
 
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

const int MAX=5100000;
long long MOD;

long long fac[MAX],finv[MAX],inv[MAX];

void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<MAX;i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

long long COM(int n,int k){
  if(n<k) return 0;
  if(n<0||k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  ll n;cin>>n;
  int p;cin>>p;

  MOD=p;
  COMinit();

  if(n>=10000000){
    cout<<-1<<endl;
    return 0;
  }

  ll ans=0;
  rep(r,0,n+1){
    ll a=n,b=r;
    ll now=1;
    while(a>0){
      ll v=a%p,w=b%p;
      now*=COM(v,w);
      now%=p;
      a/=p;b/=p;
    }
    ans+=now;
    ans%=998244353;
  }

  cout<<ans<<endl;
}
0