import sys input = sys.stdin.readline P,Q=map(int,input().split()) S=[0]*(10**6) for i in range(1,10**6): S[i]=P%i for i in range(1,10**6): S[i]=S[i]+S[i-1] LIST=[] for i in range(1,10**6): LIST.append((P//i,i)) if P//i<10**6: break LIST.reverse() LIST.append((10**9,0)) def calc(x): if x<10**6: return S[x] else: ANS=S[10**6-1] now=10**6 for i in range(1,len(LIST)): MAX=min(x,LIST[i][0]) # now~MAXの個数 ko=MAX-now+1 ANS+=P*ko-ko*(MAX+now)//2*LIST[i][1] if x<=LIST[i][0]: return ANS else: now=LIST[i][0]+1 re for i in range(Q): x,y=map(int,input().split()) minus=calc(x-1) plus=calc(y) print(plus-minus)