結果
問題 | No.2381 Gift Exchange Party |
ユーザー |
👑 |
提出日時 | 2023-07-14 22:41:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 46 ms / 2,000 ms |
コード長 | 579 bytes |
コンパイル時間 | 3,757 ms |
コンパイル使用メモリ | 230,500 KB |
実行使用メモリ | 5,632 KB |
最終ジャッジ日時 | 2024-09-16 07:45:12 |
合計ジャッジ時間 | 5,006 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
#include <bits/stdc++.h>using namespace std;#include <atcoder/all>using namespace atcoder;using mint=modint998244353;int main(void) {int n,p;cin >> n >> p;vector<mint> inv(n+1,1);vector<mint> fact(n+1,1);vector<mint> finv(n+1,1);for(int i=2;i<=n;++i){inv[i]=mint(i).inv();fact[i]=fact[i-1]*i;finv[i]=finv[i-1]*inv[i];}mint ans=fact[n];mint invpow=1;for(int i=0;i*p<=n;++i){ans-=fact[n]*invpow*finv[n-i*p]*finv[i];invpow/=p;}cout << ans.val() << endl;return 0;}