結果

問題 No.2381 Gift Exchange Party
ユーザー titiatitia
提出日時 2023-07-15 05:06:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 638 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 86,572 KB
実行使用メモリ 136,812 KB
最終ジャッジ日時 2023-10-14 19:40:23
合計ジャッジ時間 4,796 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
133,272 KB
testcase_01 WA -
testcase_02 AC 118 ms
133,352 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 116 ms
133,544 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 116 ms
133,472 KB
testcase_12 AC 117 ms
133,636 KB
testcase_13 AC 116 ms
133,352 KB
testcase_14 AC 129 ms
136,812 KB
testcase_15 AC 116 ms
133,508 KB
testcase_16 AC 119 ms
133,480 KB
testcase_17 AC 122 ms
133,536 KB
testcase_18 AC 117 ms
133,612 KB
testcase_19 AC 120 ms
133,384 KB
testcase_20 AC 165 ms
133,804 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 167 ms
133,980 KB
testcase_24 AC 117 ms
133,420 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,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

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



0