#pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #include<cstdio> #include<cmath> #include<string> #include<queue> #include<algorithm> #include<stack> #include<cstring> #include<vector> #include<list> #include<set> #include<map> #include<bitset> #include<time.h> using namespace std; #define LL long long #define pi (4*atan(1.0)) #define eps 1e-4 #define bug(x) cout<<"bug"<<x<<endl; const int N=1e5+10,M=1e6+10,inf=1e9+7,MOD=1e9+7; const LL INF=1e18+10,mod=1e9+7; struct is { int gcd,minn,num; }; struct SGT { int minn[N<<2],gcd[N<<2],num[N<<2]; void pushup(int pos) { if(minn[pos<<1]==minn[pos<<1|1]) minn[pos]=minn[pos<<1],num[pos]=num[pos<<1]+num[pos<<1|1]; else if(minn[pos<<1]<minn[pos<<1|1]) minn[pos]=minn[pos<<1],num[pos]=num[pos<<1]; else minn[pos]=minn[pos<<1|1],num[pos]=num[pos<<1|1]; gcd[pos]=__gcd(gcd[pos<<1],gcd[pos<<1|1]); } void build(int l,int r,int pos) { if(l==r) { scanf("%d",&minn[pos]); gcd[pos]=minn[pos]; num[pos]=1; return; } int mid=(l+r)>>1; build(l,mid,pos<<1); build(mid+1,r,pos<<1|1); pushup(pos); } is query(int L,int R,int l,int r,int pos) { if(L==l&&r==R)return (is){gcd[pos],minn[pos],num[pos]}; int mid=(l+r)>>1; if(L>mid)return query(L,R,mid+1,r,pos<<1|1); else if(R<=mid)return query(L,R,l,mid,pos<<1); else { is x=query(L,mid,l,mid,pos<<1); is z=query(mid+1,R,mid+1,r,pos<<1|1); int gcd=__gcd(x.gcd,z.gcd); int num,minn=1; if(x.minn==z.minn) minn=x.minn,num=x.num+z.num; else if(x.minn<z.minn) minn=x.minn,num=x.num; else minn=z.minn,num=z.num; return (is){gcd,minn,num}; } } }tree; int main() { int n; scanf("%d",&n); tree.build(1,n,1); int q; scanf("%d",&q); while(q--) { int l,r; scanf("%d%d",&l,&r); is ans=tree.query(l,r,1,n,1); //cout<<ans.minn<<" "<<ans.gcd<<endl; if(ans.minn&&ans.gcd%ans.minn==0)printf("%d\n",r-l+1-ans.num); else printf("%d\n",r-l+1); } return 0; }