結果

問題 No.2381 Gift Exchange Party
ユーザー rlangevinrlangevin
提出日時 2023-07-14 22:00:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 199 ms / 2,000 ms
コード長 683 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 86,976 KB
実行使用メモリ 84,640 KB
最終ジャッジ日時 2023-10-14 12:09:50
合計ジャッジ時間 3,928 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
83,744 KB
testcase_01 AC 87 ms
83,864 KB
testcase_02 AC 87 ms
83,644 KB
testcase_03 AC 87 ms
83,640 KB
testcase_04 AC 88 ms
83,652 KB
testcase_05 AC 85 ms
83,524 KB
testcase_06 AC 87 ms
83,932 KB
testcase_07 AC 86 ms
83,708 KB
testcase_08 AC 87 ms
83,696 KB
testcase_09 AC 85 ms
83,736 KB
testcase_10 AC 87 ms
83,728 KB
testcase_11 AC 86 ms
83,996 KB
testcase_12 AC 87 ms
83,908 KB
testcase_13 AC 87 ms
83,600 KB
testcase_14 AC 96 ms
83,908 KB
testcase_15 AC 89 ms
83,764 KB
testcase_16 AC 89 ms
83,780 KB
testcase_17 AC 87 ms
83,580 KB
testcase_18 AC 87 ms
83,576 KB
testcase_19 AC 88 ms
83,548 KB
testcase_20 AC 196 ms
84,348 KB
testcase_21 AC 89 ms
83,888 KB
testcase_22 AC 199 ms
84,556 KB
testcase_23 AC 199 ms
84,640 KB
testcase_24 AC 87 ms
83,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, P = map(int, input().split())
mod = 998244353
n = 505050
fact = [1] * (n + 1)
invfact = [1] * (n + 1)
for i in range(1, n):
    fact[i + 1] = ((i+1) * fact[i]) % mod
invfact[n] = pow(fact[n], mod - 2, mod)
for i in range(n - 1, -1, -1):
    invfact[i] = invfact[i + 1] * (i + 1) % mod

def comb(n, r):
    if n < 0 or r < 0 or n - r < 0:
        return 0
    return fact[n] * invfact[r] * invfact[n - r] % mod
    
ans = 0
nokori = N
pm = 1
now = 1
cnt = 1
while now > 0:
    ans += now
    if nokori < P:
        break
    now *= comb(nokori, P) * fact[P - 1] * pow(cnt, mod - 2, mod)
    now %= mod
    ans %= mod
    nokori -= P
    cnt += 1
    
print( (fact[N] - ans) % mod )
0