import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int p = sc.nextInt(); int q = sc.nextInt(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { int left = sc.nextInt(); int right = sc.nextInt(); long start = left; long total = (right - left + 1) * (long) p; while (start <= right) { long div = p / start; if (div == 0) { break; } long end = Math.min(p / div, right); total -= (end - start + 1) * (end + start) / 2 * div; start = end + 1; } sb.append(total).append("\n"); } System.out.print(sb); } }