結果

問題 No.2391 SAN 値チェック
ユーザー lam6er
提出日時 2025-04-16 00:52:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,065 bytes
コンパイル時間 678 ms
コンパイル使用メモリ 82,128 KB
実行使用メモリ 81,516 KB
最終ジャッジ日時 2025-04-16 00:53:42
合計ジャッジ時間 2,753 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 WA * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353
max_n = 2 * 10**5 + 10

# Precompute factorials and inverse factorials modulo MOD
fact = [1] * (max_n)
for i in range(1, max_n):
    fact[i] = fact[i-1] * i % MOD

inv_fact = [1] * (max_n)
inv_fact[max_n-1] = pow(fact[max_n-1], MOD-2, MOD)
for i in range(max_n-2, -1, -1):
    inv_fact[i] = inv_fact[i+1] * (i+1) % MOD

n = int(input())
for i in range(n + 1):
    if i == 0:
        print(0)
    else:
        # Calculate combination C(n-1, i-1)
        k = i - 1
        if k < 0 or k > n - 1:
            comb = 0
        else:
            comb = fact[n-1] * inv_fact[k] % MOD
            comb = comb * inv_fact[(n-1) - k] % MOD
        
        # Calculate inv_fact[N - i]
        ni = n - i
        if ni < 0:
            inv = 0
        else:
            inv = inv_fact[ni]
        
        # Determine the sign
        exponent = ni
        if exponent % 2 == 0:
            sign = 1
        else:
            sign = MOD - 1
        
        # Compute the result
        res = comb * inv % MOD
        res = res * sign % MOD
        print(res)
0