結果

問題 No.1886 Sum of Slide Max
ユーザー lam6er
提出日時 2025-03-20 18:52:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 258 ms / 2,000 ms
コード長 777 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 82,116 KB
実行使用メモリ 94,004 KB
最終ジャッジ日時 2025-03-20 18:53:16
合計ジャッジ時間 3,333 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 9
権限があれば一括ダウンロードができます

ソースコード

diff #

MOD = 998244353

def main():
    import sys
    input = sys.stdin.read
    N = int(input().strip())
    
    # Precompute factorials up to N+1
    max_fact = N + 1
    fact = [1] * (max_fact + 1)
    for i in range(1, max_fact + 1):
        fact[i] = fact[i-1] * i % MOD
    
    # Precompute inverse for each number 1..N+1
    max_inv = N + 1
    inv = [1] * (max_inv + 1)
    for i in range(1, max_inv + 1):
        inv[i] = pow(i, MOD-2, MOD)
    
    # Compute answers for each K
    ans = []
    for K in range(1, N + 1):
        term = K * (N - K + 1) % MOD
        term = term * fact[N+1] % MOD
        term = term * inv[K+1] % MOD
        ans.append(term)
    
    # Output each answer in order
    print('\n'.join(map(str, ans)))

if __name__ == "__main__":
    main()
0