#include using namespace std; #define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; template using V=vector; template using VV=V>; template struct BIT{ private: vector A; const int n; public: BIT(int _n) : A(_n+1,0), n(_n){} T sum(int i){ T s=0; while(i>0){ s+=A[i]; i-=i&-i; } return s; } T sum(int i,int j){ return sum(j)-sum(i-1); } void add(int i,T x){ while(i<=n){ A[i]+=x; i+=i&-i; } } void update(int i,T x){ T tmp=sum(i,i); if(tmp!=x) add(i,x-tmp); } }; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); BIT bit(1000000); int q; cin>>q; V L(q),R(q); rep(i,q) cin>>L[i]>>R[i]; V> P(q); rep(i,q) P[i]={L[i],i}; sort(ALL(P)); stack st; rep(i,q){ int j=P[i].second; st.push(j); } V ANS(q); for(int i=1000000;i>=1;i--){ bit.add(i,1); for(int j=i*2;j<=1000000;j+=i) bit.update(j,0); while(st.size() && L[st.top()]==i){ auto j=st.top(); st.pop(); ANS[j]=bit.sum(L[j],R[j]); } } rep(i,q) cout<