// #define _GLIBCXX_DEBUG // for STL debug (optional) #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 using namespace std; #define debug(...) fprintf(stderr, __VA_ARGS__) #define int long long int template void chmax(T &a, T b) {a = max(a, b);} template void chmin(T &a, T b) {a = min(a, b);} template void chadd(T &a, T b) {a = a + b;} typedef pair pii; typedef long long ll; int dx[] = {0, 0, 1, -1}; int dy[] = {1, -1, 0, 0}; const ll INF = 1001001001001001LL; const ll MOD = 1000000007LL; signed main() { int P, Q; cin >> P >> Q; while(Q--) { int l, r; cin >> l >> r; int vl = P / l, vr = P / r, cur = l; int ans = 0; for(int div=vl; div>=vr; div--) { if(div == 0) { int ll = max(l, P + 1); int rr = r; int add = 2 * P * (rr - ll + 1) / 2; ans += add; } else { int ll = max(P / (div + 1) + 1, l); int rr = min(P / div, r); int lll = P % ll, rrr = P % rr; int add = (lll + rrr) * (rr - ll + 1) / 2; ans += add; if(P / cur != P / (cur + 1)) { cur++; div = P / cur + 1; } } } cout << ans << endl; } return 0; }