import sys import math def main(): input = sys.stdin.read().split() ptr = 0 P = int(input[ptr]) ptr += 1 Q = int(input[ptr]) ptr += 1 queries = [] for _ in range(Q): L = int(input[ptr]) ptr += 1 R = int(input[ptr]) ptr += 1 queries.append((L, R)) D = int(math.isqrt(P)) # Precompute sum_A: sum_A[x] is sum_{n=1 to x} n * floor(P / n) sum_A = [0] * (D + 1) for n in range(1, D + 1): k = P // n sum_A[n] = sum_A[n-1] + n * k for L, R in queries: # Compute A: sum n*floor(P/n) for n <= D and in [L, R] A = 0 if L <= D: upper = min(R, D) if L == 1: a_sum = sum_A[upper] else: a_sum = sum_A[upper] - sum_A[L-1] A = a_sum # Compute B: sum n*floor(P/n) for n > D and in [L, R] lower = max(L, D + 1) if lower > R: B = 0 else: B = 0 for k in range(1, D + 1): n_low = (P // (k + 1)) + 1 n_high = P // k a = max(n_low, lower) b = min(n_high, R) if a > b: continue count = b - a + 1 sum_n = (a + b) * count // 2 B += k * sum_n S = A + B total = P * (R - L + 1) - S print(total) if __name__ == '__main__': main()