結果

問題 No.2381 Gift Exchange Party
ユーザー titiatitia
提出日時 2023-07-15 05:08:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 656 bytes
コンパイル時間 2,128 ms
コンパイル使用メモリ 86,624 KB
実行使用メモリ 137,336 KB
最終ジャッジ日時 2023-10-14 19:43:31
合計ジャッジ時間 5,527 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
134,216 KB
testcase_01 AC 131 ms
133,864 KB
testcase_02 AC 131 ms
133,996 KB
testcase_03 AC 130 ms
133,996 KB
testcase_04 AC 131 ms
133,972 KB
testcase_05 AC 130 ms
134,080 KB
testcase_06 AC 129 ms
134,120 KB
testcase_07 AC 129 ms
134,140 KB
testcase_08 AC 128 ms
133,764 KB
testcase_09 AC 127 ms
134,212 KB
testcase_10 AC 129 ms
133,980 KB
testcase_11 AC 127 ms
133,924 KB
testcase_12 AC 127 ms
133,972 KB
testcase_13 AC 128 ms
134,116 KB
testcase_14 AC 142 ms
137,336 KB
testcase_15 AC 129 ms
134,016 KB
testcase_16 AC 129 ms
134,000 KB
testcase_17 AC 128 ms
133,980 KB
testcase_18 AC 131 ms
133,784 KB
testcase_19 AC 129 ms
134,032 KB
testcase_20 AC 177 ms
134,460 KB
testcase_21 AC 128 ms
133,944 KB
testcase_22 AC 178 ms
134,376 KB
testcase_23 AC 178 ms
134,400 KB
testcase_24 AC 129 ms
134,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

mod=998244353

FACT=[1]
for i in range(1,4*10**5+1):
    FACT.append(FACT[-1]*i%mod)

FACT_INV=[pow(FACT[-1],mod-2,mod)]
for i in range(4*10**5,0,-1):
    FACT_INV.append(FACT_INV[-1]*i%mod)

FACT_INV.reverse()

def Combi(a,b):
    if 0<=b<=a:
        return FACT[a]*FACT_INV[b]%mod*FACT_INV[a-b]%mod
    else:
        return 0

ANS=0
x=1
if P<=N:
    for i in range(0,3*10**5):
        if i*P>N:
            break
        now=i*P

        if now-P>=0:
            x=x*Combi(now,now-P)%mod

        ANS+=x*FACT_INV[i]%mod*pow(FACT[P-1],i,mod)%mod*Combi(N,i*P)%mod
        ANS%=mod
else:
    ANS=1

print((FACT[N]-ANS)%mod)



0