#include #define rep(i, a, n) for(int i = a; i < n; i++) #define repr(i, a, b) for(int i = a; i >= b; i--) #define int long long #define all(a) a.begin(), a.end() #define chmax(x, y) x = max(x, y) #define chmin(x, y) x = min(x, y) using namespace std; typedef pair P; typedef pair PP; const int mod = 1000000007; const int INF = 2e18; int p, q, MAX; int d[100010]; vector a; vector b; int calc(int n){ if(n * n <= p) return d[n]; int res = MAX; int idx = upper_bound(a.begin(), a.end(), PP{n, {INF, INF}}) - a.begin(); idx--; res += b[idx]; int ed = a[idx].second.first; int diff = a[idx].second.second; int m = n - a[idx].first + 1; int fst = ed - diff * (m - 1); int tmp = (fst + ed) * m / 2; res += tmp; // cout << n << " " << b[idx] << " " << idx << " " << a[idx].first << ' ' << fst << ' ' << ed << ' ' << diff << ' ' << m << ' ' << tmp << endl; return res; } signed main(){ ios::sync_with_stdio(false); cin.tie(0); cin >> p >> q; for(int i = 1; i * i <= p; i++){ d[i] = d[i - 1] + p % i; } MAX = *max_element(d, d + 100010); int MAXid = max_element(d, d + 100010) - d; for(int i = 0; i * i < p; i++){ int idx = p / (i + 1) + 1; int r = p - i * idx; a.push_back({idx, {r, i}}); } sort(a.begin(), a.end()); b.resize(a.size() + 1, 0); for(int i = 0; i < a.size() - 1; i++){ int ed = a[i].second.first; int diff = a[i].second.second; int fst = ed % diff; int n = ed / diff + 1; b[i + 1] = b[i] + (fst + ed) * n / 2; } assert(a[0].first == MAXid + 1); // rep(i, 0, p + 1){ // cout << calc(i) << endl; // } rep(i, 0, q){ int l, r; cin >> l >> r; int ans = calc(r) - calc(l - 1); cout << ans << endl; } }