結果
問題 |
No.2137 Stairs of Permutation
|
ユーザー |
![]() |
提出日時 | 2025-04-16 01:12:28 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 953 bytes |
コンパイル時間 | 501 ms |
コンパイル使用メモリ | 82,052 KB |
実行使用メモリ | 68,772 KB |
最終ジャッジ日時 | 2025-04-16 01:14:12 |
合計ジャッジ時間 | 5,584 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 1 TLE * 1 -- * 21 |
ソースコード
MOD = 998244353 N = int(input()) if N == 0: print(0) else: # Compute factorial mod MOD fact = 1 for i in range(2, N + 1): fact = fact * i % MOD # Compute S1, S2, S3 using Fermat's theorem S1 = 0 S2 = 0 S3 = 0 for i in range(1, N + 1): inv_i = pow(i, MOD - 2, MOD) S1 = (S1 + inv_i) % MOD inv_i_sq = inv_i * inv_i % MOD S2 = (S2 + inv_i_sq) % MOD inv_i_cu = inv_i_sq * inv_i % MOD S3 = (S3 + inv_i_cu) % MOD # Compute the sum using the derived formula term1 = pow(S1, 3, MOD) term2 = 3 * pow(S1, 2, MOD) % MOD term3 = S1 % MOD term4 = (3 * S2) % MOD term4 = term4 * ((S1 + 1) % MOD) % MOD term5 = (2 * S3) % MOD sum_total = (term1 + term2 + term3) % MOD sum_total = (sum_total - term4) % MOD sum_total = (sum_total + term5) % MOD # Multiply by fact[N] and take mod ans = sum_total * fact % MOD print(ans)