結果

問題 No.2381 Gift Exchange Party
ユーザー ニックネームニックネーム
提出日時 2023-07-14 22:50:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 268 ms / 2,000 ms
コード長 382 bytes
コンパイル時間 1,140 ms
コンパイル使用メモリ 10,892 KB
実行使用メモリ 23,648 KB
最終ジャッジ日時 2023-10-14 13:09:33
合計ジャッジ時間 3,824 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,868 KB
testcase_01 AC 15 ms
7,952 KB
testcase_02 AC 60 ms
13,668 KB
testcase_03 AC 38 ms
10,980 KB
testcase_04 AC 81 ms
15,640 KB
testcase_05 AC 140 ms
22,724 KB
testcase_06 AC 73 ms
14,632 KB
testcase_07 AC 73 ms
14,892 KB
testcase_08 AC 120 ms
20,684 KB
testcase_09 AC 18 ms
8,484 KB
testcase_10 AC 55 ms
13,024 KB
testcase_11 AC 91 ms
16,752 KB
testcase_12 AC 27 ms
9,564 KB
testcase_13 AC 61 ms
13,308 KB
testcase_14 AC 106 ms
18,012 KB
testcase_15 AC 57 ms
12,544 KB
testcase_16 AC 58 ms
13,056 KB
testcase_17 AC 123 ms
20,464 KB
testcase_18 AC 76 ms
15,512 KB
testcase_19 AC 82 ms
15,472 KB
testcase_20 AC 257 ms
23,580 KB
testcase_21 AC 153 ms
23,592 KB
testcase_22 AC 268 ms
23,648 KB
testcase_23 AC 259 ms
23,564 KB
testcase_24 AC 70 ms
14,300 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,p = map(int,input().split())
mod = 998244353; fa = [1]*(n+1); fi = [1]*(n+1)
for i in range(1,n): fa[i+1] = fa[i]*(i+1)%mod
fi[n] = pow(fa[n],mod-2,mod)
for i in range(n,0,-1): fi[i-1] = fi[i]*i%mod
def cmb(n,r): return fa[n]*fi[n-r]%mod*fi[r]%mod if 0<=r<=n else 0
x = 1; ans = fa[n]-1
for i in range(n//p): x = x*fa[p-1]%mod*cmb(n-i*p,p)%mod; ans -= x*fi[i+1]%mod
print(ans%mod)
0