//#define _GLIBCXX_DEBUG #include #define rep(i, n) for(int i=0; i; using vs = vector; using vi = vector; using vvi = vector; template using PQ = priority_queue; template using PQG = priority_queue, greater >; const int INF = 0xccccccc; const ll LINF = 922337203685477580LL; template inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template istream &operator>>(istream &is, pair &p) { return is >> p.first >> p.second;} template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ' ' << p.second;} //head int p, q, m, u; map mp; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> p >> q; m = sqrt(p); u = p/m; for(int i = 1; i <= u; i++) { mp[i] = mp[i-1] + p%i; } for(int j = m-1; j > 0; j--) { auto x = *mp.rbegin(); int y = p/j; mp[y] = x.second + (ll)(y-x.first)*(p%y + p%(x.first+1))/2; } while(q--) { int lr[2]; cin >> lr[0] >> lr[1]; lr[0]--; ll box[2]; rep(u, 2) { map::iterator lb = mp.lower_bound(lr[u]); if(lb->first == lr[u]) box[u] = lb->second; else { lb = prev(lb); box[u] = lb->second + (ll)(lr[u]-lb->first)*(p%lr[u] + p%(lb->first+1))/2; } } cout << box[1] - box[0] << '\n'; } }