結果

問題 No.2381 Gift Exchange Party
ユーザー matsup10matsup10
提出日時 2023-07-14 23:51:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 67 ms / 2,000 ms
コード長 1,595 bytes
コンパイル時間 8,110 ms
コンパイル使用メモリ 316,608 KB
実行使用メモリ 6,476 KB
最終ジャッジ日時 2023-10-14 14:21:05
合計ジャッジ時間 10,677 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
6,264 KB
testcase_01 AC 46 ms
6,200 KB
testcase_02 AC 45 ms
6,252 KB
testcase_03 AC 45 ms
6,284 KB
testcase_04 AC 46 ms
6,288 KB
testcase_05 AC 45 ms
6,256 KB
testcase_06 AC 45 ms
6,248 KB
testcase_07 AC 46 ms
6,196 KB
testcase_08 AC 45 ms
6,288 KB
testcase_09 AC 45 ms
6,288 KB
testcase_10 AC 45 ms
6,476 KB
testcase_11 AC 45 ms
6,224 KB
testcase_12 AC 45 ms
6,360 KB
testcase_13 AC 45 ms
6,288 KB
testcase_14 AC 45 ms
6,288 KB
testcase_15 AC 46 ms
6,284 KB
testcase_16 AC 46 ms
6,252 KB
testcase_17 AC 46 ms
6,204 KB
testcase_18 AC 46 ms
6,248 KB
testcase_19 AC 45 ms
6,204 KB
testcase_20 AC 66 ms
6,324 KB
testcase_21 AC 45 ms
6,280 KB
testcase_22 AC 67 ms
6,292 KB
testcase_23 AC 67 ms
6,208 KB
testcase_24 AC 45 ms
6,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.h>
#include <atcoder/all>

using namespace std;
using ll = long long;
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,a,b) for(int i=a;i<=int(b);i++)
#define ALL(x) x.begin(),x.end()
#define INF INT_MAX
#define INFL LLONG_MAX / 4
using namespace atcoder;
using mint = modint998244353;
template<typename T> void chmin(T& a, T b) { a = min(a, b); }
template<typename T> void chmax(T& a, T b) { a = max(a, b); }
#define PR(x) cerr << #x << "=" << x << endl
using i128 = __int128_t;
struct nCkmod {
  vector<long long> fanc;
  vector<long long> fancinv;
  long long mod;

  nCkmod(long long n, long long mod_ = 998244353): fanc(n + 1), fancinv(n + 1), mod(mod_) {
    fanc[0] = 1;
    fancinv[0] = 1;
    for(long long i = 1; i <= n; i++) {
      fanc[i] = (fanc[i - 1] * i) % mod;
      fancinv[i] = (fancinv[i - 1] * modinv(i)) % mod;
    }  
  }
  long long modinv(long long a) {
    long long b = mod, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= mod;
    if (u < 0) u += mod;
    return u;
  }
  long long nck(int n, int k) {
    if(n < k) return 0;
    return fanc[n] * fancinv[k] % mod * fancinv[n - k] % mod;
  }
};

int main() {
  int n;
  ll p;
  cin >> n >> p;

  nCkmod nck(200005);

  mint ans = nck.fanc[n];
  REP(i, n / p + 1) {
    mint tmp = nck.fanc[n];
    tmp *= nck.fancinv[n-p*i];
    mint p_ = 1;
    p_ /= p;
    tmp *= p_.pow(i);
    tmp *= nck.fancinv[i];

    ans -= tmp;
    // cout << tmp.val() << endl;
  }

  cout << ans.val();



  return 0;
}
0