import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long P = sc.nextLong(); int Q = sc.nextInt(); int[] L = new int[Q]; int[] R = new int[Q]; for (int i = 0; i < Q; ++i) { L[i] = sc.nextInt(); R[i] = sc.nextInt(); } long[] sum = new long[10000000]; for (int i = 1; i < sum.length; ++i) { sum[i] = P % i + (i > 0 ? sum[i - 1] : 0); } for (int i = 0; i < Q; ++i) { int l = L[i]; int r = R[i]; long ans = 0; if (l < sum.length) { ans = sum[Math.min(sum.length - 1, r)] - sum[l - 1]; l = Math.min(sum.length, r + 1); } if (l > r) { System.out.println(ans); } else { for (long cur = l; cur <= r;) { long q = P / cur; long res = P % cur; long x = Math.min((long) ((P - cur * q - 1) / q), r - cur); // l,l+1,..,l+xが商が同じ ans = res * (x + 1) - q * x * (x + 1) / 2 + ans; cur = cur + x + 1; } System.out.println(ans); } } } static long gcd(long a, long b) { if (a > b) return gcd(b, a); if (a == 0) return b; return gcd(b % a, a); } public static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }