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 K = int(math.isqrt(P)) if P > 0 else 0 for _ in range(Q): L = int(input[ptr]) ptr += 1 R = int(input[ptr]) ptr += 1 # Adjust R if it's larger than P R_orig = R R = min(R, P) if L > R: print(0) continue total = P * (R - L + 1) S = 0 # Part a: q from 1 to K for q in range(1, K + 1): a = (P // (q + 1)) + 1 b = P // q a = max(a, L) b = min(b, R) if a > b: continue count = b - a + 1 sum_n = (a + b) * count // 2 S += q * sum_n # Part b: n from 1 to K for n in range(1, K + 1): if n < L or n > R: continue q = P // n if q <= K: continue S += n * q # Handle the case where R_orig > P if R_orig > P: # Add terms from P+1 to R_orig # Each term is P mod n = P (since n > P) # But P mod n = P - n * 0 = P # But wait, no. For n > P, P mod n = P # So sum from max(L, P+1) to R_orig of P lower = max(L, P + 1) upper = R_orig if lower <= upper: cnt = upper - lower + 1 total += P * cnt ans = total - S print(ans) if __name__ == "__main__": main()