結果

問題 No.2381 Gift Exchange Party
ユーザー flygonflygon
提出日時 2023-07-14 23:01:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 397 ms / 2,000 ms
コード長 1,086 bytes
コンパイル時間 1,144 ms
コンパイル使用メモリ 86,664 KB
実行使用メモリ 252,092 KB
最終ジャッジ日時 2023-10-14 13:26:17
合計ジャッジ時間 9,734 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 397 ms
250,364 KB
testcase_01 AC 97 ms
71,744 KB
testcase_02 AC 351 ms
251,500 KB
testcase_03 AC 96 ms
76,652 KB
testcase_04 AC 99 ms
76,800 KB
testcase_05 AC 97 ms
76,944 KB
testcase_06 AC 340 ms
251,812 KB
testcase_07 AC 96 ms
76,572 KB
testcase_08 AC 98 ms
76,940 KB
testcase_09 AC 94 ms
76,628 KB
testcase_10 AC 96 ms
76,832 KB
testcase_11 AC 357 ms
251,776 KB
testcase_12 AC 316 ms
251,432 KB
testcase_13 AC 317 ms
251,280 KB
testcase_14 AC 332 ms
251,732 KB
testcase_15 AC 320 ms
251,728 KB
testcase_16 AC 318 ms
251,728 KB
testcase_17 AC 317 ms
251,536 KB
testcase_18 AC 318 ms
251,996 KB
testcase_19 AC 324 ms
251,680 KB
testcase_20 AC 340 ms
252,044 KB
testcase_21 AC 96 ms
76,920 KB
testcase_22 AC 339 ms
251,600 KB
testcase_23 AC 334 ms
251,468 KB
testcase_24 AC 323 ms
252,092 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

n,p = map(int,input().split())
all = 1
mod = 998244353
for i in range(1,n+1):
    all *= i
    all %= mod
if p > n:
    print(all-1)
    exit()

e = 1
for i in range(1, p):
    e *= i
    e %= mod

# nCk
def com(n, mod):
    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]
    for i in range(2, n+1):
        fact.append((fact[-1]*i) % mod)
        inv.append((-inv[mod % i]*(mod//i)) % mod)
        factinv.append((factinv[-1]*inv[-1]) % mod)
    return fact, factinv

f,fi = com(10**6, mod)

def npr(n, r):
    if n < r:return 1
    return f[n] * fi[n-r] % mod
def ncr(n, r):
    if n < r:return 1
    return f[n] * fi[n-r] % mod * fi[r] % mod

# 長さ1とpのループしかないとき

mx = n//p
now = 1
all -= 1

for i in range(1,mx+1):
    now *= ncr(p*i,p)
    now *= e
    now %= mod
    all -= ncr(n,p*i) * now * fi[i]
    all %= mod

print(all)

0