#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1 << 28; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; long double PI = acos(-1); using namespace std; typedef unsigned long long ull; typedef long long ll; ll sum[10000001]; ll P, Q; ll solve(ll x) { ll res = P * x; if (x <= 10000000) res -= sum[x]; else { res -= sum[10000000]; ll i = 1; for (;; i++) { ll lf = max(P / (i + 1) + 1, 10000001LL); ll rg = min(P / i, x); //cout << x << " " << lf << " " << rg << endl; if (rg <= 10000000) break; if (lf > rg) continue; res -= i * (lf + rg) * (rg - lf + 1) / 2; } } return res; } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ scanf("%lld %lld", &P, &Q); for (ll i = 1; i <= 10000000; i++) { sum[i] = sum[i - 1]; sum[i] += P / i * i; } while (Q--) { ll l, r; scanf("%lld %lld", &l, &r); l--; ll res = solve(r); if (l) res -= solve(l); printf("%lld\n", res); } return 0; }