結果

問題 No.2381 Gift Exchange Party
ユーザー lloyzlloyz
提出日時 2023-07-21 07:19:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 517 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 81,776 KB
実行使用メモリ 64,812 KB
最終ジャッジ日時 2023-10-21 08:36:56
合計ジャッジ時間 2,753 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
53,384 KB
testcase_01 AC 35 ms
53,384 KB
testcase_02 AC 47 ms
61,120 KB
testcase_03 AC 43 ms
60,316 KB
testcase_04 AC 47 ms
61,780 KB
testcase_05 AC 49 ms
63,904 KB
testcase_06 AC 44 ms
61,480 KB
testcase_07 AC 44 ms
61,528 KB
testcase_08 AC 48 ms
63,256 KB
testcase_09 AC 38 ms
59,488 KB
testcase_10 AC 44 ms
60,964 KB
testcase_11 AC 48 ms
62,104 KB
testcase_12 AC 41 ms
59,932 KB
testcase_13 AC 44 ms
61,096 KB
testcase_14 AC 51 ms
64,812 KB
testcase_15 AC 42 ms
60,856 KB
testcase_16 AC 42 ms
60,964 KB
testcase_17 AC 46 ms
63,232 KB
testcase_18 AC 46 ms
61,660 KB
testcase_19 AC 43 ms
61,720 KB
testcase_20 AC 93 ms
64,452 KB
testcase_21 AC 49 ms
64,180 KB
testcase_22 AC 88 ms
64,524 KB
testcase_23 AC 86 ms
64,524 KB
testcase_24 AC 42 ms
61,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, p = map(int, input().split())
mod = 998244353

fact = [1] * (n + 1)
inv = [1] * (n + 1)
finv = [1] * (n + 1)
for i in range(2, n + 1):
    fact[i] = fact[i - 1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i - 1] * inv[i] % mod
inv_p = pow(p, mod - 2, mod)
ans = 0
max_k = n // p
for k in range(max_k + 1):
    res = fact[n] * finv[k] % mod
    res *= finv[n - k * p] * pow(inv_p, k, mod) % mod
    res %= mod
    ans += res
    ans %= mod
ans = (fact[n] - ans) % mod
print(ans)
0