#define CP_BUNDLED_SOURCE #ifdef TEMPLATE #else #define TEMPLATE # pragma GCC optimize("O3") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using uint=unsigned; using ll=long long; using ull=unsigned long long; using ld=long double; using pii=pair; using pll=pair; using i128=__int128; using u128=unsigned __int128; templateusing vc=vector; templateusing vvc=vc>; templateusing vvvc=vvc>; templateusing smpq=priority_queue,greater>; templateusing bipq=priority_queue; #define rep(i,n) for(ll i=0;i<(ll)(n);i++) #define REP(i,j,n) for(ll i=(j);i<(ll)(n);i++) #define DREP(i,n,m) for(ll i=(n);i>=(m);i--) #define drep(i,n) for(ll i=((n)-1);i>=0;i--) #define rall(x) x.rbegin(),x.rend() #define mp(...) make_pair(__VA_ARGS__) #define pb push_back #define fi first #define se second #define is insert #define bg begin() #define ed end() #define all(x) x.begin(),x.end() void scan(int&a) { cin >> a; } void scan(ll&a) { cin >> a; } void scan(string&a) { cin >> a; } void scan(char&a) { cin >> a; } void scan(uint&a) { cin >> a; } void scan(ull&a) { cin >> a; } void scan(bool&a) { cin >> a; } void scan(ld&a){ cin>> a;} template void scan(vector&a) { for(auto&x:a) scan(x); } void read() {} template void read(Head&head, Tail&... tail) { scan(head); read(tail...); } #define INT(...) int __VA_ARGS__; read(__VA_ARGS__); #define LL(...) ll __VA_ARGS__; read(__VA_ARGS__); #define ULL(...) ull __VA_ARGS__; read(__VA_ARGS__); #define STR(...) string __VA_ARGS__; read(__VA_ARGS__); #define VC(type, name, ...) vector name(__VA_ARGS__); read(name); #define VVC(type, name, size, ...) vector> name(size, vector(__VA_ARGS__)); read(name); templatevoid print(T a) { cout << a; } template void print(vectora) { for(int i=0;i<(int)a.size();i++){if(i)cout<<" ";print(a[i]);}cout< void PRT(T a) { print(a); cout < void PRT(Head head, Tail ... tail) { print(head); cout << " "; PRT(tail...); return; } template bool chmin(T &x, F y){ if(x>y){ x=y; return true; } return false; } template bool chmax(T &x, F y){ if(x T floor(T a, T b) { return a / b - (a % b && (a ^ b) < 0); } template T ceil(T x, T y) { return floor(x + y - 1, y); } template T bmod(T x, T y) { return x - y * floor(x, y); } template pair divmod(T x, T y) { T q = floor(x, y); return {q, x - q * y}; } void YesNo(bool b){ cout<<(b?"Yes":"No")<stovi(const string&s,const string&S){ vcv(s.size()); rep(i,s.size()){ auto t=S.find(s[i]); assert(t!=string::npos); v[i]=t; } return v; } template T isqrt(T x){ T F=sqrtl(x); while((F+1)*(F+1)<=x)F++; while(F*F>x)F--; return F; } template vvctrans(const vvc&a){ assert(a.size()&&a[0].size()); vvcb(a[0].size(),vc(a.size())); rep(i,a.size())rep(j,a[0].size()){ b[j][i]=a[i][j]; } return b; } template vctrans(const vc&a){ assert(a.size()&&a[0].size()); vcb(a[0].size(),string(a.size(),0)); rep(i,a.size())rep(j,a[0].size()){ b[j][i]=a[i][j]; } return b; } template int popcount(T n){ return __builtin_popcountll(n); } template L sum(vc&a){ return accumulate(all(a),L(0)); } template vcsubset(T S){ vcans; for(T x=S;x>0;x=(x-1)&S)ans.pb(x); ans.pb(0); return ans; } template T max(vc&a){ return *max_element(all(a)); } template T min(vc&a){ return *min_element(all(a)); } #ifndef COMPRESSER_STRUCT #define COMPRESSER_STRUCT template struct compresser{ vcx; compresser(int n=0){x.reserve(n);} compresser(const vc&xs){ x=xs; } void push(T p){built=false;x.pb(p);} bool built=false; void build(){ if(!chmax(built,1))return; sort(all(x)); x.erase(unique(all(x)),x.end()); } int find(T v){ build(); auto itr=lower_bound(all(x),v)-x.begin(); if(itr==x.size()||x[itr]!=v)return -1; return itr; } int find_next(T v){ build(); return lower_bound(all(x),v)-x.begin(); } int size(){ build(); return x.size(); } T operator[](int i)const{ assert(0<=i&&i vc presum(vc &a){ vc ret(a.size()+1); rep(i,a.size())ret[i+1]=ret[i]+a[i]; return ret; } template vc &operator+=(vc &a,F b){ for (auto&v:a)v += b; return a; } template vc &operator-=(vc&a,F b){ for (auto&v:a)v-=b; return a; } template vc &operator*=(vc&a,F b){ for (auto&v:a)v*=b; return a; } template constexpr T pow(T a,T b){ T res=1; while(b){ if(b&1)res*=a; a*=a; b/=2; } return res; } constexpr ll ten(ll a){ return pow(10,a); } templateconstexpr T inf=numeric_limits::max()/2-1; template int tbit(T x){ using U=make_unsigned_t; U y=(U)x; return y?(int)bit_width(y)-1:-1; } template int lbit(T x){ using U=make_unsigned_t; U y=(U)x; return y?(int)countr_zero(y):-1; } template int tbit(T x,int p){ using U=make_unsigned_t; constexpr int W=numeric_limits::digits; U y=(U)x; if(p<0)return -1; if(p>=W-1)return tbit(y); return tbit(y&((U(1)<<(p+1))-1)); } template int lbit(T x,int p){ using U=make_unsigned_t; constexpr int W=numeric_limits::digits; U y=(U)x; if(p<0)return lbit(y); if(p>=W)return -1; return lbit(y&(~U(0)<>(istream&is,i128&x){ string s;is>>s; x=0; int i=0,neg=0; if(s[0]=='-')neg=1,i=1; for(;i<(int)s.size();i++)x=x*10+s[i]-'0'; if(neg)x=-x; return is; } ostream& operator<<(ostream&os,i128 x){ if(x==0)return os<<0; if(x<0)os<<"-"; u128 y=x<0?-(u128)x:(u128)x; string s; while(y)s.pb('0'+y%10),y/=10; reverse(all(s)); return os<sync_with_stdio(0); #ifdef LOCAL cout<big_block; vcpattern; constexpr static inline int B=64; int n; bit_vector()=default; bit_vector(const vc&v):n(v.size()){ big_block.assign((n+B-1)/B+1,0); pattern.assign(big_block.size()+1,0); REP(i,1,big_block.size()){ u64 val=0; uint shift=0; uint lim=min(v.size(),i*B); REP(l,(i-1)*B,lim){ assert(v[l]==0||v[l]==1); val+=(u64)v[l]<<(shift++); } big_block[i]=big_block[i-1]+__builtin_popcountll(val); pattern[i-1]=val; } } //[0,r) int rank1(int r)const{ assert(0<=r&&r<=n); int res=big_block[r/B]; res+=__builtin_popcountll(pattern[r/B]&((u64(1)<<(r%B))-1)); return res; } int rank1(int l,int r)const{ assert(0<=l&&l<=r&&r<=n); return rank1(r)-rank1(l); } int rank0(int r)const{ assert(0<=r&&r<=n); return r-rank1(r); } int rank0(int l,int r)const{ assert(0<=l&&l<=r&&r<=n); return r-l-rank1(l,r); } }; template struct wm_base{ using U=make_unsigned_t; int n; arraybv; arraymid; vcgi; void build(vca){ gi=a,n=a.size(); vcsend(n); drep(bit,D){ rep(i,n)send[i]=a[i]>>bit&1; bv[bit]=bit_vector(send); vcl,r; rep(i,n){ if(a[i]>>bit&1)r.pb(a[i]); else l.pb(a[i]); } mid[bit]=l.size(); l.insert(l.end(),all(r)); a=move(l); } } template void build_info(F f){ auto a=gi; vcidx(n); rep(i,n)idx[i]=i; f(a,idx,D); drep(bit,D){ vcl,r; vcli,ri; rep(i,n){ if(a[i]>>bit&1)r.pb(a[i]),ri.pb(idx[i]); else l.pb(a[i]),li.pb(idx[i]); } l.insert(l.end(),all(r)); li.insert(li.end(),all(ri)); a=move(l); idx=move(li); f(a,idx,bit); } } template static array,D+1>& lower_pref(){ static array,D+1>pref; return pref; } template void buildlowersum(const vc&W){ auto&pref=lower_pref(); build_info([&](const vc&a,const vc&idx,int bit){ pref[bit]=vc(n+1); rep(i,n)pref[bit][i+1]=pref[bit][i]+W[idx[i]]; }); } struct node{ int bit,l,r; int size()const{return r-l;} }; struct child_type{ bool has; node zero,one; }; child_type child(node x)const{ if(x.bit==-1)return {false,{},{}}; int a0=bv[x.bit].rank0(x.l); int b0=bv[x.bit].rank0(x.r); int a1=x.l-a0,b1=x.r-b0; return {true,{x.bit-1,a0,b0},{x.bit-1,mid[x.bit]+a1,mid[x.bit]+b1}}; } T kth_smallest(int l,int r,int k)const{ T ans=0; node x={D-1,l,r}; while(x.bit!=-1){ child_type ch=child(x); if(ch.zero.size()<=k){ k-=ch.zero.size(); ans+=T(1)<>x.bit&1)ans+=ch.zero.size(),x=ch.one; else x=ch.zero; } return ans; } //[l,r) [d,u) ll count(int l,int r,T d,T u)const{ return count_less(l,r,u)-count_less(l,r,d); } template L lower_sum(int l,int r,T u)const{ auto&pref=lower_pref(); L ans=0; node x={D-1,l,r}; while(x.bit!=-1){ child_type ch=child(x); if(u>>x.bit&1){ ans+=pref[x.bit][ch.zero.r]-pref[x.bit][ch.zero.l]; x=ch.one; }else x=ch.zero; } return ans; } template L lower_sum(int l,int r,T d,T u)const{ return lower_sum(l,r,u)-lower_sum(l,r,d); } }; template struct ninfo{ arraymf_; bool built_=0; void buildp(){ if(built_)return; built_=1; REP(i,1,N)mf_[i]=i; REP(i,2,N){ if(mf_[i]==i&&i*i>factorize(int n){ assert(0>res; while(n>1){ int tar=mf_[n]; res.pb({tar,0}); while(n%tar==0){ n/=tar; res.back().second++; } } return res; } vcdiv(int n){ vcres{1}; for(auto [p,e]:factorize(n)){ int sz=res.size(),pw=1; rep(i,e){ pw*=p; rep(j,sz)res.pb(res[j]*pw); } } sort(all(res)); return res; } int mobius(int n){ auto pf=factorize(n); for(auto [p,e]:pf)if(e>1)return 0; return pf.size()%2?-1:1; } bool is_prime(int n){ assert(0<=n&&n=2&&mf_[n]==n; } int phi(int n){ ll res=n; while(n>1){ res*=mf_[n]-1; res/=mf_[n]; int M=mf_[n]; while(n%M==0)n/=M; } return res; } }; void solve(){ INT(q); const int N=ten(6)+10; ninfonin; nin.buildp(); vcvs(N); REP(i,1,N){ vs[i]=i/nin.mf_[i]; } vs[1]=0; wm_basewms(N);wms.build(vs); while(q--){ LL(l,r); ++r; PRT(wms.count_less(l,r,l)); } } signed main(){ int t=1; // cin >> t; while(t--)solve(); }