#ifndef LOCAL #include using namespace std; #define debug(...) (void(0)) #else #include "algo/debug.h" #endif int64_t arith(int64_t a0, int64_t d, int64_t len) { return (2ll * a0 + (len - 1) * d) * len / 2; } void solve() { int P, Q; cin >> P >> Q; constexpr int M = 1e9 + 4; vector thr; vector sum; for (int64_t i = 1; i < M;) { int64_t lo = i, hi = M; while (hi > lo + 1) { int64_t mi = (lo + hi) / 2; (P / mi == P / i ? lo : hi) = mi; } thr.push_back(i); sum.push_back(arith(P % i, -P / i, lo - i + 1)); if (i == hi) break; i = hi; } vector pref(sum.size() + 1); for (unsigned i{}; i < sum.size(); i++) pref[i + 1] = pref[i] + sum[i]; const auto g = [&](int r) -> int64_t { if(r <= 0) return 0; int hi = r, lo = 0; while (hi > lo + 1) { int mi = (hi + lo) / 2; (P / mi == P / r ? hi : lo) = mi; } int k = distance(thr.begin(), lower_bound(thr.begin(), thr.end(), hi)); int64_t ans = pref[k]; ans += arith(P % hi, -P / hi, r - hi + 1); return ans; }; while (Q--) { int l, r; cin >> l >> r; int64_t ans = g(r) - g(l - 1); cout << ans << endl; } } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int tt = 1; // std::cin >> tt; while (tt--) { solve(); } }