結果
問題 |
No.2127 Mod, Sum, Sum, Mod
|
ユーザー |
![]() |
提出日時 | 2022-10-27 20:52:43 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 58 ms / 2,000 ms |
コード長 | 655 bytes |
コンパイル時間 | 318 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 71,168 KB |
最終ジャッジ日時 | 2024-07-05 05:52:58 |
合計ジャッジ時間 | 2,410 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
import math n, m = map(int, input().split()) mod = 998244353 t = (int)(math.sqrt(n)) ans = n * (n + 1) // 2 * m % mod j = 1 while j < t and j <= m: nj = n // j ans -= j * nj * (n + 1) ans %= mod ans += nj * (nj + 1) // 2 * j * j ans %= mod j += 1 nj, nt = 1, n // t while nj <= nt: l = max(t, (n + nj + 1) // (nj + 1)) r = min(m, n // nj) if l > r: nj += 1 continue ll = l * (l - 1) // 2 rr = r * (r + 1) // 2 ans -= (n + 1) * nj * (rr - ll) ans %= mod ans += nj * (nj + 1) * (rr * (2 * r + 1) - ll * (2 * l - 1)) // 6 ans %= mod nj += 1 if ans < 0: ans += mod print(ans)