結果

問題 No.2381 Gift Exchange Party
ユーザー eve__fuyuki
提出日時 2023-10-10 17:19:05
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 600 bytes
コンパイル時間 2,196 ms
コンパイル使用メモリ 197,880 KB
最終ジャッジ日時 2025-02-17 06:39:11
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/modint>
#include <bits/stdc++.h>
using namespace std;

using mint = atcoder::modint998244353;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, p;
    cin >> n >> p;
    vector<mint> fact(n + 1, 1);
    for (int i = 2; i <= n; i++) {
        fact[i] = fact[i - 1] * i;
    }
    mint ans = 1;
    mint pat = 1;
    for (int i = 0; i < n / p; i++) {
        pat *= fact[n - i * p] / (fact[p] * fact[n - (i + 1) * p]);
        pat *= fact[p - 1];
        pat /= (i + 1);
        ans += pat;
    }
    ans = fact[n] - ans;
    cout << ans.val() << endl;
}
0