結果
問題 | No.752 mod数列 |
ユーザー |
|
提出日時 | 2018-11-10 00:21:19 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 430 ms / 2,000 ms |
コード長 | 1,152 bytes |
コンパイル時間 | 2,124 ms |
コンパイル使用メモリ | 193,284 KB |
最終ジャッジ日時 | 2025-01-06 16:18:53 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 31 |
ソースコード
//================================= // Created on: 2018/11/09 21:30:39 //================================= #include <bits/stdc++.h> using ll = long long; constexpr ll MAX = 10000000; constexpr int NUM = 100; ll small[MAX + 1], start[NUM + 1], end[NUM + 1]; int main() { std::cin.tie(0); std::ios::sync_with_stdio(false); ll P; int Q; std::cin >> P >> Q; for (ll i = 1; i <= MAX; i++) { small[i] = small[i - 1] + (P % i); } for (ll i = NUM; i >= 1; i--) { start[i] = P / (i + 1) + 1, end[i] = P / i; } auto get = [&](ll ind) { ll ans = 0; if (ind > P) { ans += (ind - P) * P, ind = P; } if (ind <= MAX) { return ans + small[ind]; } ans += small[MAX]; for (int i = NUM; i >= 1 and start[i] <= ind; i--) { const ll S = std::max(MAX + 1, start[i]), T = std::min(end[i], ind); if (S > T) { continue; } ans += (2 * P - (P / S) * (S + T)) * (T - S + 1) / 2; } return ans; }; for (int q = 0; q < Q; q++) { ll L, R; std::cin >> L >> R; std::cout << get(R) - get(L - 1) << std::endl; } return 0; }