結果

問題 No.2141 Enumeratest
ユーザー lam6er
提出日時 2025-03-20 19:02:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 734 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 83,012 KB
実行使用メモリ 75,260 KB
最終ジャッジ日時 2025-03-20 19:02:52
合計ジャッジ時間 3,305 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353

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

if M == 0:
    print(1 % mod)
else:
    max_fact = M
    # Precompute factorial and inverse factorial modulo
    fact = [1] * (max_fact + 1)
    for i in range(1, max_fact + 1):
        fact[i] = fact[i-1] * i % mod
    
    inv_fact = [1] * (max_fact + 1)
    inv_fact[max_fact] = pow(fact[max_fact], mod - 2, mod)
    for i in range(max_fact - 1, -1, -1):
        inv_fact[i] = inv_fact[i+1] * (i+1) % mod
    
    q = M // N
    r = M % N
    
    part1 = pow(inv_fact[q], N - r, mod)
    if r == 0:
        part2 = 1
    else:
        part2 = pow(inv_fact[q + 1], r, mod)
    
    denominator_inv = (part1 * part2) % mod
    ans = (fact[M] * denominator_inv) % mod
    print(ans)
0