#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define endl '\n'
#define ll long long int
#define md 1000000007
#define MP make_pair
#define pb push_back
#define ppb pop_back
const ll INF=1e9+15;
const ll NAX= 1e5+5; // change it acc tothe contraints
vector<ll> arr(NAX);
struct node{
int num=0;
int cnt=1;
/* node(){
num=0;
cnt=0;
_gcd=0;
}
node (int val){
num=val;
}
void merge(node &root, node &left, node& right){
_gcd=gcd();
}
*/
};
node null_n;
//node tree[4*NAX];
vector<node> tree;
int gcd(int a,int b)
{
{int t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
}
void merge(node &root, node &left, node &right){
int gcd_num=gcd(left.num, right.num);
root.num=gcd_num;
int cnt_now=0;
debug(root.cnt, root.num, gcd_num);
if(left.num==gcd_num){
cnt_now+=left.cnt;
//cnt_now+=1;
root.cnt=cnt_now;
}
if(right.num==gcd_num){
cnt_now+=right.cnt;
//cnt_now+=1;
root.cnt=cnt_now;
}
debug(root.num,left.num, right.num, root.cnt, left.cnt, right.cnt);
}
void build(ll si, ll ss,ll se){
if(ss==se){
tree[si].cnt=0;
tree[si].num=arr[ss];
return;
}
int mid=(ss+se)/2;
int lc=2*si;
int rc=2*si+1;
build(2*si, ss,mid);
build(2*si+1, mid+1,se);
merge(tree[si],tree[lc],tree[rc]);
//tree[si]=__gcd(tree[lc], tree[rc]);
//debug(tree[si].open_need, tree[si].close_need, tree[si].len);
}
void printTree(int i,int l,int r){
cout<<"id= "<<i<<" "<<"num: "<<tree[i].num<<" "<<"count: "<<tree[i].cnt<<endl;
//<<" "<<"clse_need: "<<tree[i].close_need<<endl;
if(l==r){
return;
}
int mid = (l+r)/2 ;
int left = i*2,right = i*2+1;
printTree(left,l,mid);
printTree(right,mid+1,r);
}
node query(ll root,ll node_low, ll node_high, ll query_low, ll query_high){
if(node_low>=query_low and query_high>=node_high){
return tree[root];
}
if(query_low>node_high or node_low>query_high){
return null_n;
}
node ans;
ll mid=(node_low+node_high)/2;
node lc=query(2*root, node_low, mid, query_low, query_high);
node rc=query(2*root+1, mid+1, node_high, query_low, query_high);
merge(ans, lc, rc);
return ans;
}
/*void update(ll root, ll node_low, ll node_high, ll query_low, ll query_high, ll val){
if(node_low>=query_low and query_high>=node_high){
tree[root]=val;
return;
}
if(query_low>node_high or node_low>query_high){
return ;
}
ll mid=(node_low+node_high)/2;
update(2*root, node_low, mid, query_low, query_high, val);
update(2*root+1, mid+1, node_high, query_low, query_high, val);
tree[root]=__gcd(tree[2*root],tree[2*root+1]);
}
*/
void solve()
{
ll n, q;
cin>>n;
for(int i=0; i<n; i++){
cin>>arr[i];
}
/* while(__builtin_popcount(n)!=1){
arr.pb(0);
n++;
}
*/
tree.resize(4*NAX);
cin>>q;
build(1,0,n-1);
printTree(1,0,n-1);
while(q--){
ll l,r;
cin>>l>>r;
l--;
r--;
//debug(tree[0]);
// cout<<2*query(1,0,n-1, l,r).len<<endl;
ll no_ant=0;
no_ant=r-l;
ll answer=0;
ll cnt_now=query(1,0,n-1,l,r).cnt;
if(cnt_now==no_ant)answer+=1;
cout<<no_ant-answer<<endl;
debug(no_ant, answer, cnt_now);
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int tc=1;
// cin>>tc;
for (int i=0; i<tc; i++){
solve();
//cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2luY2x1ZGU8ZXh0L3BiX2RzL2Fzc29jX2NvbnRhaW5lci5ocHA+IAojaW5jbHVkZTxleHQvcGJfZHMvdHJlZV9wb2xpY3kuaHBwPiAKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKdm9pZCBfX3ByaW50KGludCB4KSB7Y2VyciA8PCB4O30Kdm9pZCBfX3ByaW50KGxvbmcgeCkge2NlcnIgPDwgeDt9CnZvaWQgX19wcmludChsb25nIGxvbmcgeCkge2NlcnIgPDwgeDt9CnZvaWQgX19wcmludCh1bnNpZ25lZCB4KSB7Y2VyciA8PCB4O30Kdm9pZCBfX3ByaW50KHVuc2lnbmVkIGxvbmcgeCkge2NlcnIgPDwgeDt9CnZvaWQgX19wcmludCh1bnNpZ25lZCBsb25nIGxvbmcgeCkge2NlcnIgPDwgeDt9CnZvaWQgX19wcmludChmbG9hdCB4KSB7Y2VyciA8PCB4O30Kdm9pZCBfX3ByaW50KGRvdWJsZSB4KSB7Y2VyciA8PCB4O30Kdm9pZCBfX3ByaW50KGxvbmcgZG91YmxlIHgpIHtjZXJyIDw8IHg7fQp2b2lkIF9fcHJpbnQoY2hhciB4KSB7Y2VyciA8PCAnXCcnIDw8IHggPDwgJ1wnJzt9CnZvaWQgX19wcmludChjb25zdCBjaGFyICp4KSB7Y2VyciA8PCAnXCInIDw8IHggPDwgJ1wiJzt9CnZvaWQgX19wcmludChjb25zdCBzdHJpbmcgJngpIHtjZXJyIDw8ICdcIicgP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2hhbmdlIGl0IGFjYyB0b3RoZSBjb250cmFpbnRzCiAKCnZlY3RvcjxsbD4gYXJyKE5BWCk7CgoKc3RydWN0IG5vZGV7CiAgICBpbnQgbnVtPTA7CiAgICBpbnQgY250PTE7CiAgLyogIG5vZGUoKXsKICAgICAgICBudW09MDsKICAgICAgICBjbnQ9MDsKICAgICAgICBfZ2NkPTA7CiAgICB9CiAgICBub2RlIChpbnQgdmFsKXsKICAgICAgICBudW09dmFsOwogICAgfQoKICAgIHZvaWQgbWVyZ2Uobm9kZSAmcm9vdCwgbm9kZSAmbGVmdCwgbm9kZSYgcmlnaHQpewogICAgICAgIF9nY2Q9Z2NkKCk7CiAgICB9CiAgICAqLwp9OwoKbm9kZSBudWxsX247Ci8vbm9kZSB0cmVlWzQqTkFYXTsKdmVjdG9yPG5vZGU+IHRyZWU7CgppbnQgZ2NkKGludCBhLGludCBiKQp7CiAgICB7aW50IHQ7d2hpbGUoYil7YT1hJWI7dD1hO2E9YjtiPXQ7fXJldHVybiBhO30KfQoKdm9pZCBtZXJnZShub2RlICZyb290LCAgbm9kZSAmbGVmdCwgIG5vZGUgJnJpZ2h0KXsKICAgIGludCBnY2RfbnVtPWdjZChsZWZ0Lm51bSwgcmlnaHQubnVtKTsKICAgIHJvb3QubnVtPWdjZF9udW07CiAgICBpbnQgY250X25vdz0wOwogICAgZGVidWcocm9vdC5jbnQsIHJvb3QubnVtLCBnY2RfbnVtKTsKICAgIGlmKGxlZnQubnVtPT1nY2RfbnVtKXsKICAgICAgICBjbnRfbm93Kz1sZWZ0LmNudDsKICAgICAgICAvL2NudF9ub3crPTE7CiAgICAgICAgcm9vdC5jbnQ9Y250X25vdzsKICAgIH0KICAgIGlmKHJpZ2h0Lm51bT09Z2NkX251bSl7CiAgICAgICAgY250X25vdys9cmlnaHQuY250OwogICAgICAgIC8vY250X25vdys9MTsKICAgICAgICByb290LmNudD1jbnRfbm93OwogICAgfQogICAgZGVidWcocm9vdC5udW0sbGVmdC5udW0sIHJ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SgyKnJvb3QrMSwgbWlkKzEsIG5vZGVfaGlnaCwgcXVlcnlfbG93LCBxdWVyeV9oaWdoLCB2YWwpOwogICAgIHRyZWVbcm9vdF09X19nY2QodHJlZVsyKnJvb3RdLHRyZWVbMipyb290KzFdKTsKfQogKi8Kdm9pZCBzb2x2ZSgpCnsKICAgbGwgbiwgcTsKICAgY2luPj5uOwogICBmb3IoaW50IGk9MDsgaTxuOyBpKyspewogICAgICAgY2luPj5hcnJbaV07CiAgIH0KICAgLyogd2hpbGUoX19idWlsdGluX3BvcGNvdW50KG4pIT0xKXsKICAgICAgYXJyLnBiKDApOwogICAgICBuKys7CiAgICB9CiAgICAqLwogICAgdHJlZS5yZXNpemUoNCpOQVgpOwogICAgY2luPj5xOwogICAgYnVpbGQoMSwwLG4tMSk7CiAgICBwcmludFRyZWUoMSwwLG4tMSk7CiAgICB3aGlsZShxLS0pewogICAgICAgIGxsIGwscjsKICAgICAgICBjaW4+Pmw+PnI7CiAgICAgICAgbC0tOwogICAgICAgIHItLTsKICAgIC8vZGVidWcodHJlZVswXSk7CiAgICAgLy8gICBjb3V0PDwyKnF1ZXJ5KDEsMCxuLTEsIGwscikubGVuPDxlbmRsOwogICAgICAgIGxsIG5vX2FudD0wOwogICAgICAgICBub19hbnQ9ci1sOwogICAgICAgIGxsIGFuc3dlcj0wOwogICAgICAgIGxsIGNudF9ub3c9cXVlcnkoMSwwLG4tMSxsLHIpLmNudDsKICAgICAgICBpZihjbnRfbm93PT1ub19hbnQpYW5zd2VyKz0xOwogICAgICAgIGNvdXQ8PG5vX2FudC1hbnN3ZXI8PGVuZGw7CiAgICAgICAgZGVidWcobm9fYW50LCBhbnN3ZXIsIGNudF9ub3cpOwogICAgfSAgIAogCiAKIAogCn0KaW50IG1haW4oKSB7CgkJCiBpb3M6OnN5bmNfd2l0aF9zdGRpbygwKSwgY2luLnRpZSgwKSwgY291dC50aWUoMCk7CiAKaW50IHRjPTE7CiAgIC8vIGNpbj4+dGM7CiAgICBmb3IgKGludCBpPTA7IGk8dGM7IGkrKyl7CgkJc29sdmUoKTsKCQkvL2NlcnIgPDwgInRpbWUgdGFrZW4gOiAiIDw8IChmbG9hdCljbG9jaygpIC8gQ0xPQ0tTX1BFUl9TRUMgPDwgIiBzZWNzIiA8PCBlbmRsOwogCgkJfQoJCQogCiAKfQogCg==