import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np P,Q = map(int, readline().split()) m = map(int,read().split()) LR = zip(m,m) M = 30000 low_max = P//(M+1) if low_max < 0: low_max = 0 lower = np.cumsum(P % np.arange(low_max + 1, dtype=np.int64)) left = P // np.arange(1, M+2, dtype=np.int64) right = P // np.arange(0, M+1, dtype=np.int64) S = (right - left) * (right + left + 1) // 2 upper = P * (right - left) - np.arange(M+1, dtype=np.int64) * S upper[0] = 0 upper = upper[::-1].cumsum()[::-1] lower = lower.tolist() upper = upper.tolist() upper.append(0) def F(N): if N <= low_max: return lower[N] if N > P: return upper[0] + lower[-1] + (N - P) * P n = P // N x = lower[-1] + upper[n+1] # 商 n+1 以上 L = P // (n+1) return x + P * (N - L) - (N - L) * (N + L + 1) // 2 * n for L,R in LR: print(F(R) - F(L-1))