結果
問題 | No.2381 Gift Exchange Party |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:09:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 135 ms / 2,000 ms |
コード長 | 950 bytes |
コンパイル時間 | 198 ms |
コンパイル使用メモリ | 82,364 KB |
実行使用メモリ | 68,924 KB |
最終ジャッジ日時 | 2025-03-20 21:09:53 |
合計ジャッジ時間 | 2,292 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 |
ソースコード
MOD = 998244353n, p = map(int, input().split())if n == 0:print(0)exit()# Precompute factorial and inverse factorialmax_n = nfact = [1] * (max_n + 1)for i in range(1, max_n + 1):fact[i] = fact[i-1] * i % MODinv_fact = [1] * (max_n + 1)inv_fact[max_n] = pow(fact[max_n], MOD-2, MOD)for i in range(max_n-1, -1, -1):inv_fact[i] = inv_fact[i+1] * (i+1) % MODm_max = n // p# Precompute pow_p and inv_pow_ppow_p = [1] * (m_max + 1)for i in range(1, m_max + 1):pow_p[i] = pow_p[i-1] * p % MODinv_pow_p = [1] * (m_max + 1)for i in range(0, m_max + 1):inv_pow_p[i] = pow(pow_p[i], MOD-2, MOD) if i != 0 else 1total = 0for m in range(0, m_max + 1):s = n - m * pif s < 0:continueterm = fact[n]term = term * inv_fact[s] % MODterm = term * inv_fact[m] % MODterm = term * inv_pow_p[m] % MODtotal = (total + term) % MODans = (fact[n] - total + MOD) % MODprint(ans)