結果

問題 No.2381 Gift Exchange Party
ユーザー cho435cho435
提出日時 2023-07-14 22:02:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 3,959 ms
コンパイル使用メモリ 261,200 KB
実行使用メモリ 81,296 KB
最終ジャッジ日時 2023-10-14 12:14:01
合計ジャッジ時間 8,671 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
80,996 KB
testcase_01 AC 137 ms
81,232 KB
testcase_02 AC 139 ms
80,996 KB
testcase_03 AC 136 ms
81,000 KB
testcase_04 AC 139 ms
80,992 KB
testcase_05 AC 145 ms
81,000 KB
testcase_06 AC 143 ms
81,148 KB
testcase_07 AC 137 ms
81,056 KB
testcase_08 AC 137 ms
81,160 KB
testcase_09 AC 138 ms
81,048 KB
testcase_10 AC 141 ms
81,296 KB
testcase_11 AC 141 ms
81,164 KB
testcase_12 AC 139 ms
81,108 KB
testcase_13 AC 144 ms
81,144 KB
testcase_14 AC 144 ms
81,112 KB
testcase_15 AC 143 ms
81,292 KB
testcase_16 AC 140 ms
81,292 KB
testcase_17 AC 141 ms
81,140 KB
testcase_18 AC 143 ms
81,276 KB
testcase_19 AC 140 ms
80,996 KB
testcase_20 AC 163 ms
81,224 KB
testcase_21 AC 141 ms
81,232 KB
testcase_22 AC 161 ms
80,988 KB
testcase_23 AC 162 ms
81,100 KB
testcase_24 AC 142 ms
81,216 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using mint = atcoder::modint998244353;

// combination MOD
const int MOD=998244353;
const int MAX_N=5e6;
vector<mint> fac(MAX_N+1,1);
vector<mint> finv(MAX_N+1,1);
vector<ll> inv(MAX_N+1,1);
void comb_setup(){
	for(int i=2;i<=MAX_N;i++){
		fac.at(i)=(fac.at(i-1)*i);
		inv.at(i)=MOD-(inv.at(MOD%i)*(MOD/i))%MOD;
		finv.at(i)=(finv.at(i-1)*inv.at(i));
	}
}
mint comb(ll n,ll k){
	if(n<k) return 0;
	return fac.at(n)*finv.at(n-k)*finv.at(k);
}

int main(){
	comb_setup();
	ll n,p;
	cin>>n>>p;
	mint ans=fac.at(n);
	for(ll i=0;i*p<=n;i++){
		mint tmp=comb(n,i*p);
		tmp*=fac.at(i*p);
		tmp*=finv.at(i);
		tmp/=mint(p).pow(i);
		ans-=tmp;
	}
	cout<<ans.val()<<endl;
}
0