結果

問題 No.2381 Gift Exchange Party
ユーザー titiatitia
提出日時 2023-07-15 05:07:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 654 bytes
コンパイル時間 497 ms
コンパイル使用メモリ 86,460 KB
実行使用メモリ 137,288 KB
最終ジャッジ日時 2023-10-14 19:41:45
合計ジャッジ時間 4,830 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
134,004 KB
testcase_01 AC 127 ms
134,276 KB
testcase_02 AC 123 ms
134,200 KB
testcase_03 AC 123 ms
133,896 KB
testcase_04 AC 120 ms
133,996 KB
testcase_05 AC 123 ms
134,040 KB
testcase_06 AC 122 ms
133,852 KB
testcase_07 AC 121 ms
134,044 KB
testcase_08 AC 122 ms
133,996 KB
testcase_09 AC 121 ms
133,928 KB
testcase_10 AC 123 ms
133,764 KB
testcase_11 AC 128 ms
133,912 KB
testcase_12 AC 122 ms
134,204 KB
testcase_13 AC 123 ms
134,040 KB
testcase_14 AC 136 ms
137,288 KB
testcase_15 AC 122 ms
133,740 KB
testcase_16 AC 124 ms
134,064 KB
testcase_17 AC 126 ms
133,768 KB
testcase_18 AC 125 ms
134,040 KB
testcase_19 AC 122 ms
134,172 KB
testcase_20 AC 170 ms
134,228 KB
testcase_21 AC 122 ms
134,052 KB
testcase_22 WA -
testcase_23 AC 173 ms
134,344 KB
testcase_24 AC 124 ms
133,708 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
else:
    ANS=1

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



0