結果

問題 No.2381 Gift Exchange Party
ユーザー ああいいああいい
提出日時 2023-07-14 23:04:54
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 595 bytes
コンパイル時間 925 ms
コンパイル使用メモリ 86,976 KB
実行使用メモリ 80,036 KB
最終ジャッジ日時 2023-10-14 13:29:31
合計ジャッジ時間 4,867 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
77,408 KB
testcase_01 AC 71 ms
71,396 KB
testcase_02 AC 81 ms
77,496 KB
testcase_03 AC 79 ms
77,396 KB
testcase_04 AC 77 ms
77,424 KB
testcase_05 RE -
testcase_06 AC 79 ms
77,420 KB
testcase_07 AC 75 ms
77,568 KB
testcase_08 RE -
testcase_09 AC 80 ms
77,444 KB
testcase_10 AC 78 ms
77,520 KB
testcase_11 RE -
testcase_12 AC 80 ms
77,416 KB
testcase_13 AC 80 ms
77,564 KB
testcase_14 RE -
testcase_15 AC 80 ms
77,472 KB
testcase_16 AC 80 ms
77,444 KB
testcase_17 RE -
testcase_18 AC 80 ms
77,340 KB
testcase_19 AC 78 ms
77,380 KB
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 AC 79 ms
77,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

N,P = map(int,input().split())
mod = 998244353

if N == 1:
    print(0)
    exit()
    

C = 10 ** 5 + 100
fact = [1] * C
fact_inv = [1] * C
for i in range(2,C):
    fact[i] = fact[i-1] * i % mod
fact_inv[-1] = pow(fact[-1],mod - 2,mod)
for i in range(C - 2,1,-1):
    fact_inv[i] = fact_inv[i + 1] * (i + 1) % mod

ans = 1
k = 1
r = pow(P,mod - 2,mod)
while k * P  <= N:
    #ans += fact[N] * pow(fact_inv[P],k,mod) * fact[k] % mod
    ans += fact[N] * fact_inv[N - k * P] % mod * pow(r,k,mod) * fact_inv[k] % mod
    ans %= mod
    k += 1
ans = fact[N] - ans
ans %= mod
print(ans)
0