import std.conv, std.functional, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.container, std.math, std.numeric, std.range, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } enum B = 10^^7; enum C = 10^^2; long P; int Q; long[] L, R; void main() { try { for (; ; ) { P = readLong(); Q = readInt(); L = new long[Q]; R = new long[Q]; foreach (q; 0 .. Q) { L[q] = readLong(); R[q] = readLong(); } auto sum = new long[B + 2]; sum[1] = 0; foreach (n; 1 .. B + 1) { sum[n + 1] = sum[n] + P % n; } foreach (q; 0 .. Q) { long ans; // 1 <= n <= B { const a = cast(int)(max(L[q], 1)); const b = cast(int)(min(R[q], B)); if (a <= b) { ans += (sum[b + 1] - sum[a]); } } // floor(P / n) = c // c n <= P < (c + 1) n foreach (c; 0 .. C + 1) { const a = max(P / (c + 1) + 1, L[q], B + 1); const b = (c == 0) ? R[q] : min(P / c, R[q]); if (a <= b) { ans += P * (b - a + 1); ans -= c * ((a + b) * (b - a + 1) / 2); } } writeln(ans); } } } catch (EOFException e) { } }