結果

問題 No.2381 Gift Exchange Party
ユーザー sasa8uyauya
提出日時 2024-09-14 13:00:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 230 ms / 2,000 ms
コード長 292 bytes
コンパイル時間 527 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 90,396 KB
最終ジャッジ日時 2024-09-14 13:00:21
合計ジャッジ時間 4,219 ms
ジャッジサーバーID
(参考情報)
judge6 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます

ソースコード

diff #

n,p=map(int,input().split())
M=998244353
fa=[1,1]
fb=[1,1]
for i in range(2,n+1):
  fa+=[fa[-1]*i%M]
  fb+=[fb[-1]*(M//i)*fb[M%i]*fa[M%i-1]*(-1)%M]
if n<p:
  print((fa[n]-1)%M)
  exit()
a=fa[n]
for i in range(n//p+1):
  a-=fa[n]*pow(fb[p],i,M)*fb[i]*fb[n-p*i]*pow(fa[p-1],i,M)
  a%=M
print(a)
0