import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] first = br.readLine().split(" ", 2); int p = Integer.parseInt(first[0]); int q = Integer.parseInt(first[1]); StringBuilder sb = new StringBuilder(); for (int i = 0; i < q; i++) { String[] line = br.readLine().split(" ", 2); int left = Integer.parseInt(line[0]); int right = Integer.parseInt(line[1]); 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); } }