import bisect import copy import decimal import fractions import heapq import itertools import math import random import sys import time from collections import Counter,deque,defaultdict from functools import lru_cache,reduce from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max def _heappush_max(heap,item): heap.append(item) heapq._siftdown_max(heap, 0, len(heap)-1) def _heappushpop_max(heap, item): if heap and item < heap[0]: item, heap[0] = heap[0], item heapq._siftup_max(heap, 0) return item from math import gcd as GCD read=sys.stdin.read readline=sys.stdin.readline readlines=sys.stdin.readlines write=sys.stdout.write class Cumsum: def __init__(self,lst,mod=0): self.N=len(lst) self.mod=mod self.cumsum=[0]*(self.N+1) self.cumsum[0]=0 for i in range(1,self.N+1): self.cumsum[i]=self.cumsum[i-1]+lst[i-1] if self.mod: self.cumsum[i]%=self.mod def __getitem__(self,i): if type(i)==int: if 0<=i1: mid=(ok+ng)//2 if is_ok(mid): ok=mid else: ng=mid return ok P,Q=map(int,readline().split()) M=10**5 A=[0]+[P//n for n in range(1,M)] PP=A[-1]+1 for i in range(1,M): A[i]*=i bound=[10**9+1]+[P//n+1 for n in range(1,PP+1)] B=[(bound[i]-bound[i+1])*(bound[i]+bound[i+1]-1)//2*i for i in range(PP)] A=Cumsum(A) B=Cumsum(B) def S(c): if c<=M: return A[:c] def is_ok(x): return c>=bound[x] x=Bisect_Int(PP,-1,is_ok) return A[:bound[PP]]+B[x:]+(x-1)*(c-bound[x])*(bound[x]+c-1)//2 for q in range(Q): L,R=map(int,readline().split()) R+=1 ans=P*(R-L)-(S(R)-S(L)) print(ans)