#include using namespace std; typedef long long ll; #define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i) #define ALL(v) (v).begin(),(v).end() #define CLR(t,v) memset(t,(v),sizeof(t)) templateostream& operator<<(ostream& os,const pair&a){return os<<"("<void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<void chmin(T&a,const T&b){if(a>b)a=b;} templatevoid chmax(T&a,const T&b){if(a 0; i--) { ll x = P / (i+1); ll y = P / (i); ll a = P % (x+1); ll d = -(P / y); // cout << "(" << x << "," << y << "]" << " d=" << d << " a=" << a << " "; if (y <= N) { ll n = y - x; ll w = (2*a+(n-1)*d)*n/2; // cout << n << " " << w << endl; ans += w; } else { ll n = N - x; ll w = (2*a+(n-1)*d)*n/2; // cout << n << " " << w << endl; ans += w; break; } } // cout << "f(" << N << ")=" << ans << endl; return ans; } int main2() { P = nextLong(); ll Q = nextLong(); init(); REP(i, Q) { ll L = nextLong(); ll R = nextLong(); ll ans = f(R) - f(L-1); cout << ans << '\n'; } return 0; } int main() { // int n = 23; // for (int k = 1; k <= n; k++) { // cout << k << " : " << (n / k) << " " << (n % k) << endl; // } // return 0; #ifdef LOCAL for (;!cin.eof();cin>>ws) #endif main2(); return 0; }