結果
| 問題 |
No.752 mod数列
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-11-10 00:04:58 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,127 bytes |
| コンパイル時間 | 1,998 ms |
| コンパイル使用メモリ | 194,228 KB |
| 最終ジャッジ日時 | 2025-01-06 16:18:17 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 WA * 14 |
ソースコード
//=================================
// 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], end[NUM];
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 - 1; i >= 1; i--) { start[i] = P / (i + 1) + 1, end[i] = P / i; }
auto get = [&](const ll ind) {
if (ind <= MAX) { return small[ind]; }
ll ans = small[MAX];
for (int i = NUM - 1; i >= 1 and start[i] <= ind; i--) {
if (start[i] > end[i]) { continue; }
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;
}