#include <bits/stdc++.h>

using namespace std;

#define int long long

#define mid (lf + rg >> 1)
#define right (left | 1)
#define left (v << 1)

#define pb push_back
#define mp make_pair
#define nd second
#define st first

typedef long long ll;
typedef pair < int, int > pii;

const ll linf = 1e18 + 9;
const int inf = 1e9 + 9;
const int N = 1e5 + 9;
const int kokn = sqrt(N);

int n, a[N], q, l, r, ans[N], tree[4*N];

pii tree2[4*N];

bool cmp(pair < int, pii > a, pair < int, pii > b) {
  if (a.st / kokn != b.st / kokn) {
    return a.st / kokn < b.st / kokn;
  }
  return a.nd.st < b.nd.st;
}

int build(int v, int lf, int rg) {
  if (lf == rg) {
    return tree[v] = a[lf];
  }
  return tree[v] = __gcd(build(left, lf, mid), build(right, mid+1, rg));
}

pii build2(int v, int lf, int rg) {
  if (lf == rg) {
    return tree2[v] = mp(a[lf], 1);
  }
  pii t1 = build2(left, lf, mid);
  pii t2 = build2(right, mid+1, rg);
  tree2[v].st = min(t1.st, t2.st);
  if (t1.st == t2.st) {
    tree2[v].nd = t1.nd + t2.nd;
  } else {
    if (tree2[v].st == t1.st) {
      tree2[v].nd = t1.nd;
    } else {
      tree2[v].nd = t2.nd;
    }
  }
  return tree2[v];
}

int query(int v, int lf, int rg, int l, int r) {
  if (l > rg or r < lf) {
    return -1;
  }
  if (l <= lf and rg <= r) {
    return tree[v];
  }
  int t1 = query(left, lf, mid, l, r);
  int t2 = query(right, mid+1, rg, l, r);
  if (t1 == -1) {
    return t2;
  } else if (t2 == -1) {
    return t1;
  }
  return __gcd(t1, t2);
}

pii query2(int v, int lf, int rg, int l, int r) {
  if (l > rg or r < lf) {
    return mp(inf, inf);
  }
  if (l <= lf and rg <= r) {
    return tree2[v];
  }
  pii t1 = query2(left, lf, mid, l, r);
  pii t2 = query2(right, mid+1, rg, l, r);
  if (t1.st == t2.st) {
    return mp(t1.st, t1.nd + t2.nd);
  }
  if (t1.st < t2.st) {
    return t1;
  }
  return t2;
}

 main() {

  scanf("%lld", &n);

  for (int i = 1; i <= n; i++) {
    scanf("%lld", &a[i]);
  }
  scanf("%lld", &q);
  build(1, 1, n);
  build2(1, 1, n);
  for (int i = 1; i <= q; i++) {
    scanf("%lld %lld", &l, &r);
    int t1 = query(1, 1, n, l, r);
    pii t2 = query2(1, 1, n, l, r);
    if (t1 != t2.st) {
      printf("%lld\n", r - l + 1);
    } else {
      printf("%lld\n", (r - l + 1) - t2.nd);
    }
  }

  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

#define mid (lf + rg >> 1)
#define right (left | 1)
#define left (v << 1)

#define pb push_back
#define mp make_pair
#define nd second
#define st first

typedef long long ll;
typedef pair < int, int > pii;

const ll linf = 1e18 + 9;
const int inf = 1e9 + 9;
const int N = 1e5 + 9;
const int kokn = sqrt(N);

int n, a[N], q, l, r, ans[N], tree[4*N], tree2[4*N], hash[N];

vector < pii > temp;

pair < int, pii > Q[N];

bool cmp(pair < int, pii > a, pair < int, pii > b) {
	if (a.st / kokn != b.st / kokn) {
		return a.st / kokn < b.st / kokn;
	}
	return a.nd.st < b.nd.st;
}

int build(int v, int lf, int rg) {
	if (lf == rg) {
		return tree[v] = a[lf];
	}
	return tree[v] = __gcd(build(left, lf, mid), build(right, mid+1, rg));
}

int build2(int v, int lf, int rg) {
	if (lf == rg) {
		return tree2[v] = a[lf];
	}
	return tree2[v] = min(build2(left, lf, mid), build2(right, mid+1, rg));
}

int query(int v, int lf, int rg, int l, int r) {
	if (l > rg or r < lf) {
		return -1;
	}
	if (l <= lf and rg <= r) {
		return tree[v];
	}
	int t1 = query(left, lf, mid, l, r);
	int t2 = query(right, mid+1, rg, l, r);
	if (t1 == -1) {
		return t2;
	} else if (t2 == -1) {
		return t1;
	}
	return __gcd(t1, t2);
}

int query2(int v, int lf, int rg, int l, int r) {
	if (l > rg or r < lf) {
		return inf;
	}
	if (l <= lf and rg <= r) {
		return tree2[v];
	}
	int t1 = query2(left, lf, mid, l, r);
	int t2 = query2(right, mid+1, rg, l, r);
	return min(t1, t2);
}

 main() {

	scanf("%lld", &n);

	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
		temp.pb(mp(a[i], i));
	}
	int t = 0;
	sort(temp.begin(), temp.end());
	for (int i = 0; i < temp.size(); i++) {
		if (i and (temp[i].st == temp[i-1].st)) {
			a[temp[i].nd] = t;
		} else {
			a[temp[i].nd] = ++t;
		}
	}
	scanf("%lld", &q);
	build(1, 1, n);
	build2(1, 1, n);
	for (int i = 1; i <= q; i++) {
		scanf("%lld %lld", &l, &r);
		Q[i] = mp(l, mp(r, i));
	}
	sort(Q+1, Q+q+1, cmp);
	l = 0;
	r = 0;
	for (int i = 1; i <= q; i++) {
		int lf = Q[i].st;
		int rg = Q[i].nd.st;
		int t1 = query(1, 1, n, lf, rg);
		int t2 = query2(1, 1, n, lf, rg);
		while (l < lf) {
			hash[a[l++]]--;
		}
		while (l > lf) {
			hash[a[--l]]++;
		}
		while (r < rg) {
			hash[a[++r]]++;
		}
		while (r > rg) {
			hash[a[r--]]--;
		}
		if (t1 != t2) {
			ans[Q[i].nd.nd] = rg - lf + 1;
		} else {
			ans[Q[i].nd.nd] = (rg - lf + 1) - hash[t1];
		}
	}
	for (int i = 1; i <= q; i++) {
		printf("%lld\n", ans[i]);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mid (lf + rg >> 1)
#define right (left | 1)
#define left (v << 1)

#define pb push_back
#define mp make_pair
#define nd second
#define st first

typedef long long ll;
typedef pair < int, int > pii;

const ll linf = 1e18 + 9;
const int inf = 1e9 + 9;
const int N = 1e5 + 9;
const int kokn = sqrt(N);

int n, a[N], q, l, r, ans[N], tree[4*N], tree2[4*N], hash[N];

vector < pii > temp;

pair < int, pii > Q[N];

bool cmp(pair < int, pii > a, pair < int, pii > b) {
	if (a.st / kokn != b.st / kokn) {
		return a.st / kokn < b.st / kokn;
	}
	return a.nd.st < b.nd.st;
}

int build(int v, int lf, int rg) {
	if (lf == rg) {
		return tree[v] = a[lf];
	}
	return tree[v] = __gcd(build(left, lf, mid), build(right, mid+1, rg));
}

int build2(int v, int lf, int rg) {
	if (lf == rg) {
		return tree2[v] = a[lf];
	}
	return tree2[v] = min(build2(left, lf, mid), build2(right, mid+1, rg));
}

int query(int v, int lf, int rg, int l, int r) {
	if (l > rg or r < lf) {
		return -1;
	}
	if (l <= lf and rg <= r) {
		return tree[v];
	}
	int t1 = query(left, lf, mid, l, r);
	int t2 = query(right, mid+1, rg, l, r);
	if (t1 == -1) {
		return t2;
	} else if (t2 == -1) {
		return t1;
	}
	return __gcd(t1, t2);
}

int query2(int v, int lf, int rg, int l, int r) {
	if (l > rg or r < lf) {
		return inf;
	}
	if (l <= lf and rg <= r) {
		return tree2[v];
	}
	int t1 = query2(left, lf, mid, l, r);
	int t2 = query2(right, mid+1, rg, l, r);
	return min(t1, t2);
}

int main() {

	scanf("%d", &n);

	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		temp.pb(mp(a[i], i));
	}
	int t = 0;
	sort(temp.begin(), temp.end());
	for (int i = 0; i < temp.size(); i++) {
		if (i and (temp[i].st == temp[i-1].st)) {
			a[temp[i].nd] = t;
		} else {
			a[temp[i].nd] = ++t;
		}
	}
	scanf("%d", &q);
	build(1, 1, n);
	build2(1, 1, n);
	for (int i = 1; i <= q; i++) {
		scanf("%d %d", &l, &r);
		Q[i] = mp(l, mp(r, i));
	}
	sort(Q+1, Q+q+1, cmp);
	l = 0;
	r = 0;
	for (int i = 1; i <= q; i++) {
		int lf = Q[i].st;
		int rg = Q[i].nd.st;
		int t1 = query(1, 1, n, lf, rg);
		int t2 = query2(1, 1, n, lf, rg);
		while (l < lf) {
			hash[a[l]]--;
			l++;
		}
		while (l > lf) {
			l--;
			hash[a[l]]++;
		}
		while (r < rg) {
			r++;
			hash[a[r]]++;
		}
		while (r > rg) {
			hash[a[r]]--;
			r--;
		}
		if (t1 != t2) {
			ans[Q[i].nd.nd] = rg - lf + 1;
		} else {
			ans[Q[i].nd.nd] = (rg - lf + 1) - hash[t1];
		}
	}
	for (int i = 1; i <= q; i++) {
		printf("%d\n", ans[i]);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

#define mid (lf + rg >> 1)
#define right (left | 1)
#define left (v << 1)

#define pb push_back
#define mp make_pair
#define nd second
#define st first

typedef long long ll;
typedef pair < int, int > pii;

const ll linf = 1e18 + 9;
const int inf = 1e9 + 9;
const int N = 1e5 + 9;
const int kokn = sqrt(N);

int n, a[N], q, l, r, ans[N], tree[4*N], tree2[4*N], hash[N];

vector < pii > temp;

pair < int, pii > Q[N];

bool cmp(pair < int, pii > a, pair < int, pii > b) {
	if (a.st / kokn != b.st / kokn) {
		return a.st / kokn < b.st / kokn;
	}
	return a.nd.st < b.nd.st;
}

int build(int v, int lf, int rg) {
	if (lf == rg) {
		return tree[v] = a[lf];
	}
	return tree[v] = __gcd(build(left, lf, mid), build(right, mid+1, rg));
}

int build2(int v, int lf, int rg) {
	if (lf == rg) {
		return tree2[v] = a[lf];
	}
	return tree2[v] = min(build2(left, lf, mid), build2(right, mid+1, rg));
}

int query(int v, int lf, int rg, int l, int r) {
	if (l > rg or r < lf) {
		return -1;
	}
	if (l <= lf and rg <= r) {
		return tree[v];
	}
	int t1 = query(left, lf, mid, l, r);
	int t2 = query(right, mid+1, rg, l, r);
	if (t1 == -1) {
		return t2;
	} else if (t2 == -1) {
		return t1;
	}
	return __gcd(t1, t2);
}

int query2(int v, int lf, int rg, int l, int r) {
	if (l > rg or r < lf) {
		return inf;
	}
	if (l <= lf and rg <= r) {
		return tree2[v];
	}
	int t1 = query2(left, lf, mid, l, r);
	int t2 = query2(right, mid+1, rg, l, r);
	return min(t1, t2);
}

main() {

	scanf("%lld", &n);

	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
		temp.pb(mp(a[i], i));
	}
	int t = 0;
	sort(temp.begin(), temp.end());
	for (int i = 0; i < temp.size(); i++) {
		if (i and (temp[i].st == temp[i-1].st)) {
			a[temp[i].nd] = t;
		} else {
			a[temp[i].nd] = ++t;
		}
	}
	scanf("%lld", &q);
	build(1, 1, n);
	build2(1, 1, n);
	for (int i = 1; i <= q; i++) {
		scanf("%lld %lld", &l, &r);
		Q[i] = mp(l, mp(r, i));
	}
	sort(Q+1, Q+q+1, cmp);
	l = 0;
	r = 0;
	for (int i = 1; i <= q; i++) {
		int lf = Q[i].st;
		int rg = Q[i].nd.st;
		int t1 = query(1, 1, n, lf, rg);
		int t2 = query2(1, 1, n, lf, rg);
		while (l < lf) {
			hash[a[l]]--;
			l++;
		}
		while (l > lf) {
			l--;
			hash[a[l]]++;
		}
		while (r < rg) {
			r++;
			hash[a[r]]++;
		}
		while (r > rg) {
			hash[a[r]]--;
			r--;
		}
		if (t1 != t2) {
			ans[Q[i].nd.nd] = rg - lf + 1;
		} else {
			ans[Q[i].nd.nd] = (rg - lf + 1) - hash[t1];
		}
	}
	for (int i = 1; i <= q; i++) {
		printf("%lld\n", ans[i]);
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define mid (lf + rg >> 1)
#define right (left | 1)
#define left (v << 1)

#define pb push_back
#define mp make_pair
#define nd second
#define st first

typedef long long ll;
typedef pair < int, int > pii;

const ll linf = 1e18 + 9;
const int inf = 1e9 + 9;
const int N = 1e5 + 9;
const int kokn = sqrt(N);

int n, a[N], q, l, r, ans[N], tree[4*N], tree2[4*N], hash[N];

vector < pii > temp;

pair < int, pii > Q[N];

bool cmp(pair < int, pii > a, pair < int, pii > b) {
  if (a.st / kokn != b.st / kokn) {
    return a.st / kokn < b.st / kokn;
  }
  return a.nd.st < b.nd.st;
}

int build(int v, int lf, int rg) {
  if (lf == rg) {
    return tree[v] = a[lf];
  }
  return tree[v] = __gcd(build(left, lf, mid), build(right, mid+1, rg));
}

int build2(int v, int lf, int rg) {
  if (lf == rg) {
    return tree2[v] = a[lf];
  }
  return tree2[v] = min(build2(left, lf, mid), build2(right, mid+1, rg));
}

int query(int v, int lf, int rg, int l, int r) {
  if (l > rg or r < lf) {
    return -1;
  }
  if (l <= lf and rg <= r) {
    return tree[v];
  }
  int t1 = query(left, lf, mid, l, r);
  int t2 = query(right, mid+1, rg, l, r);
  if (t1 == -1) {
    return t2;
  } else if (t2 == -1) {
    return t1;
  }
  return __gcd(t1, t2);
}

int query2(int v, int lf, int rg, int l, int r) {
  if (l > rg or r < lf) {
    return inf;
  }
  if (l <= lf and rg <= r) {
    return tree2[v];
  }
  int t1 = query2(left, lf, mid, l, r);
  int t2 = query2(right, mid+1, rg, l, r);
  return min(t1, t2);
}

int main() {

  scanf("%d", &n);

  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    temp.pb(mp(a[i], i));
  }
  int t = 0;
  sort(temp.begin(), temp.end());
  for (int i = 0; i < temp.size(); i++) {
    if (i and (temp[i].st == temp[i-1].st)) {
      a[temp[i].nd] = t;
    } else {
      a[temp[i].nd] = ++t;
    }
  }
  scanf("%d", &q);
  build(1, 1, n);
  build2(1, 1, n);
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &l, &r);
    Q[i] = mp(l, mp(r, i));
  }
  sort(Q+1, Q+q+1, cmp);
  l = 0;
  r = 0;
  for (int i = 1; i <= q; i++) {
    int lf = Q[i].st;
    int rg = Q[i].nd.st;
    int t1 = query(1, 1, n, lf, rg);
    int t2 = query2(1, 1, n, lf, rg);
    while (l < lf) {
      hash[a[l++]]--;
    }
    while (l > lf) {
      hash[a[--l]]++;
    }
    while (r < rg) {
      hash[a[++r]]++;
    }
    while (r > rg) {
      hash[a[r--]]--;
    }
    if (t1 != t2) {
      ans[Q[i].nd.nd] = rg - lf + 1;
    } else {
      ans[Q[i].nd.nd] = (rg - lf + 1) - hash[t1];
    }
  }
  for (int i = 1; i <= q; i++) {
    printf("%d\n", ans[i]);
  }

  return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <cstring>
#include <iomanip>
#include <cctype>
#include <map>

using namespace std;

const int N = 100005;

pair<long,int> ST[4 * N + 10];

int qs,qe;

void build(vector<long> &v,int x,int y,int n) {
    if(x == y) {
        ST[n].first = v[x];
        ST[n].second = 1;
    }
    else {
        build(v, x, (x + y)/2, 2 * n);
        build(v,(x + y)/2 + 1, y, 2 * n + 1);
        if(ST[2 * n].first == ST[2 * n + 1].first) {
            ST[n].first = ST[2 * n].first;
            ST[n].second = ST[2 * n].second + ST[2 * n + 1].second;
        }
        else
            ST[n] = min(ST[2 * n],ST[2 * n + 1]);
    }
}

#define INFY 1000000001

pair<long,int> query(int x,int y,int n) {
    if(qs > y || qe < x) return make_pair(INFY,0);
    else if(x >= qs && y <= qe) return ST[n];
    else {
        pair<long,int> l = query(x,(x + y)/2, 2 * n);
        pair<long,int> r = query((x + y)/2 + 1, y, 2 * n + 1);
        if(l.first == r.first)
            return make_pair(l.first, l.second + r.second);
        else
            return min(l, r);
    }
}

long gcd(long a,long b) {
    if(a && !b) return a;
    else if(!a && b) return b;
    while(a - b) {
        if(a > b) a-=b;
        else b-=a;
    }
    return a;
}

long GST[4 * N + 10];

void buildG(vector<long> &v,int x,int y,int n) {
    if(x == y) GST[n] = v[x];
    else {
        buildG(v, x, (x + y)/2, 2 * n);
        buildG(v,(x + y)/2 + 1, y, 2 * n + 1);
        GST[n] = gcd(GST[2 * n], GST[2 * n + 1]);
    }
}

long queryG(int x,int y,int n) {
    if(qs > y || qe < x) return 0;
    else if(x >= qs && y <= qe) return GST[n];
    else return gcd(queryG(x,(x + y)/2,2 * n), queryG((x + y)/2 + 1, y, 2 * n + 1));

}

int main() {
    int n; cin>>n;
    vector<long> v(n + 1);
    for(int i = 1;i <= n;i++) cin>>v[i];
    buildG(v,1,n,1);
    build(v,1,n,1);
    int m; cin>>m;
    while(m--) {
        int a,b; cin>>a>>b;
        qs = a,qe = b;
        long g = queryG(1,n,1);
        pair<long,int> mn = query(1,n,1);
        if(mn.first == g) {
            cout<<(b - a + 1 - mn.second)<<endl;
        }
        else {
            cout<<(b - a + 1)<<endl;
        }

    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <cstring>
#include <iomanip>
#include <cctype>
#include <map>

using namespace std;

const int N = 100005;

pair<long,int> ST[4 * N + 10];

int qs,qe;

void build(vector<long> &v,int x,int y,int n) {
    if(x == y) {
        ST[n].first = v[x];
        ST[n].second = 1;
    }
    else {
        build(v, x, (x + y)/2, 2 * n);
        build(v,(x + y)/2 + 1, y, 2 * n + 1);
        if(ST[2 * n].first == ST[2 * n + 1].first) {
            ST[n].first = ST[2 * n].first;
            ST[n].second = ST[2 * n].second + ST[2 * n + 1].second;
        }
        else
            ST[n] = min(ST[2 * n],ST[2 * n + 1]);
    }
}

#define INFY 1000000001

pair<long,int> query(int x,int y,int n) {
    if(qs > y || qe < x) return make_pair(INFY,0);
    else if(x >= qs && y <= qe) return ST[n];
    else {
        pair<long,int> l = query(x,(x + y)/2, 2 * n);
        pair<long,int> r = query((x + y)/2 + 1, y, 2 * n + 1);
        if(l.first == r.first)
            return make_pair(l.first, l.second + r.second);
        else
            return min(l, r);
    }
}

long gcd(long a,long b) {
    if(a && !b) return a;
    else if(!a && b) return b;
    while(a - b) {
        if(a > b) a-=b;
        else b-=a;
    }
    return a;
}

long GST[4 * N + 10];

void buildG(vector<long> &v,int x,int y,int n) {
    if(x == y) GST[n] = v[x];
    else {
        buildG(v, x, (x + y)/2, 2 * n);
        buildG(v,(x + y)/2 + 1, y, 2 * n + 1);
        GST[n] = gcd(GST[2 * n], GST[2 * n + 1]);
    }
}

long queryG(int x,int y,int n) {
    if(qs > y || qe < x) return 0;
    else if(x >= qs && y <= qe) return GST[n];
    else return gcd(queryG(x,(x + y)/2,2 * n), queryG((x + y)/2 + 1, y, 2 * n + 1));

}

int main() {
    int n; cin>>n;
    vector<long> v(n + 1);
    for(int i = 1;i <= n;i++) scanf("%d",&v[i]);
    buildG(v,1,n,1);
    build(v,1,n,1);
    int m; cin>>m;
    while(m--) {
        int a,b;
        scanf("%d %d",&a,&b);
        qs = a,qe = b;
        long g = queryG(1,n,1);
        pair<long,int> mn = query(1,n,1);
        if(mn.first == g) {
            printf("%d \n",b - a + 1 - mn.second);
        }
        else {
            printf("%d \n",b - a + 1);

        }

    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <cstring>
#include <iomanip>
#include <cctype>
#include <map>

using namespace std;

const int N = 100005;

pair<long,int> ST[4 * N + 10];

int qs,qe;

void build(vector<long> &v,int x,int y,int n) {
    if(x == y) {
        ST[n].first = v[x];
        ST[n].second = 1;
    }
    else {
        build(v, x, (x + y)/2, 2 * n);
        build(v,(x + y)/2 + 1, y, 2 * n + 1);
        if(ST[2 * n].first == ST[2 * n + 1].first) {
            ST[n].first = ST[2 * n].first;
            ST[n].second = ST[2 * n].second + ST[2 * n + 1].second;
        }
        else
            ST[n] = min(ST[2 * n],ST[2 * n + 1]);
    }
}

#define INFY 1000000001

pair<long,int> query(int x,int y,int n) {
    if(qs > y || qe < x) return make_pair(INFY,0);
    else if(x >= qs && y <= qe) return ST[n];
    else {
        pair<long,int> l = query(x,(x + y)/2, 2 * n);
        pair<long,int> r = query((x + y)/2 + 1, y, 2 * n + 1);
        if(l.first == r.first)
            return make_pair(l.first, l.second + r.second);
        else
            return min(l, r);
    }
}

long gcd(long a,long b) {
    if(a && !b) return a;
    else if(!a && b) return b;
    while(a - b) {
        if(a > b) a-=b;
        else b-=a;
    }
    return a;
}

long GST[4 * N + 10];

void buildG(vector<long> &v,int x,int y,int n) {
    if(x == y) GST[n] = v[x];
    else {
        buildG(v, x, (x + y)/2, 2 * n);
        buildG(v,(x + y)/2 + 1, y, 2 * n + 1);
        GST[n] = gcd(GST[2 * n], GST[2 * n + 1]);
    }
}

long queryG(int x,int y,int n) {
    if(qs > y || qe < x) return 0;
    else if(x >= qs && y <= qe) return GST[n];
    else return gcd(queryG(x,(x + y)/2,2 * n), queryG((x + y)/2 + 1, y, 2 * n + 1));

}

int main() {
    int n; cin>>n;
    vector<long> v(n + 1);
    for(int i = 1;i <= n;i++) scanf("%d",&v[i]);
    buildG(v,1,n,1);
    build(v,1,n,1);
    int m; cin>>m;
    while(m--) {
        int a,b;
        scanf("%d %d",&a,&b);
        qs = a,qe = b;
        long g = queryG(1,n,1);
        pair<long,int> mn = query(1,n,1);
        if(mn.first == g) {
            cout<<(b - a + 1 - mn.second)<<endl;
        }
        else {
            cout<<(b - a + 1)<<endl;
        }

    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <cstring>
#include <iomanip>
#include <cctype>
#include <map>

using namespace std;

const int N = 100005;

pair<long,int> ST[4 * N + 10];

int qs,qe;

void build(vector<long> &v,int x,int y,int n) {
    if(x == y) {
        ST[n].first = v[x];
        ST[n].second = 1;
    }
    else {
        build(v, x, (x + y)/2, 2 * n);
        build(v,(x + y)/2 + 1, y, 2 * n + 1);
        if(ST[2 * n].first == ST[2 * n + 1].first) {
            ST[n].first = ST[2 * n].first;
            ST[n].second = ST[2 * n].second + ST[2 * n + 1].second;
        }
        else
            ST[n] = min(ST[2 * n],ST[2 * n + 1]);
    }
}

#define INFY 1000000001

pair<long,int> query(int x,int y,int n) {
    if(qs > y || qe < x) return make_pair(INFY,0);
    else if(x >= qs && y <= qe) return ST[n];
    else {
        pair<long,int> l = query(x,(x + y)/2, 2 * n);
        pair<long,int> r = query((x + y)/2 + 1, y, 2 * n + 1);
        if(l.first == r.first)
            return make_pair(l.first, l.second + r.second);
        else
            return min(l, r);
    }
}

long gcd(long a,long b) {
    if(a && !b) return a;
    else if(!a && b) return b;
    while(a - b) {
        if(a > b) a-=b;
        else b-=a;
    }
    return a;
}

long GST[4 * N + 10];

void buildG(vector<long> &v,int x,int y,int n) {
    if(x == y) GST[n] = v[x];
    else {
        buildG(v, x, (x + y)/2, 2 * n);
        buildG(v,(x + y)/2 + 1, y, 2 * n + 1);
        GST[n] = gcd(GST[2 * n], GST[2 * n + 1]);
    }
}

long queryG(int x,int y,int n) {
    if(qs > y || qe < x) return 0;
    else if(x >= qs && y <= qe) return GST[n];
    else return gcd(queryG(x,(x + y)/2,2 * n), queryG((x + y)/2 + 1, y, 2 * n + 1));

}

int main() {
    ios_base::sync_with_stdio(false);
    int n; cin>>n;
    vector<long> v(n + 1);
    for(int i = 1;i <= n;i++) cin>>v[i];
    buildG(v,1,n,1);
    build(v,1,n,1);
    int m; cin>>m;
    while(m--) {
        int a,b; cin>>a>>b;
        qs = a,qe = b;
        long g = queryG(1,n,1);
        pair<long,int> mn = query(1,n,1);
        if(mn.first == g) {
            cout<<(b - a + 1 - mn.second)<<endl;
        }
        else {
            cout<<(b - a + 1)<<endl;
        }

    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <cstring>
#include <iomanip>
#include <cctype>
#include <map>

using namespace std;

const int N = 100005;

pair<long,int> ST[4 * N + 10];

int qs,qe;

long v[100001];

void build(int x,int y,int n) {
    if(x == y) {
        ST[n].first = v[x];
        ST[n].second = 1;
    }
    else {
        build( x, (x + y)/2, 2 * n);
        build((x + y)/2 + 1, y, 2 * n + 1);
        if(ST[2 * n].first == ST[2 * n + 1].first) {
            ST[n].first = ST[2 * n].first;
            ST[n].second = ST[2 * n].second + ST[2 * n + 1].second;
        }
        else
            ST[n] = min(ST[2 * n],ST[2 * n + 1]);
    }
}

#define INFY 1000000001

pair<long,int> query(int x,int y,int n) {
    if(qs > y || qe < x) return make_pair(INFY,0);
    else if(x >= qs && y <= qe) return ST[n];
    else {
        pair<long,int> l = query(x,(x + y)/2, 2 * n);
        pair<long,int> r = query((x + y)/2 + 1, y, 2 * n + 1);
        if(l.first == r.first)
            return make_pair(l.first, l.second + r.second);
        else
            return min(l, r);
    }
}

long gcd(long a,long b) {
    return a == 0 ? b : gcd(b % a,a);
}

long GST[4 * N + 10];

void buildG(int x,int y,int n) {
    if(x == y) GST[n] = v[x];
    else {
        buildG(x, (x + y)/2, 2 * n);
        buildG((x + y)/2 + 1, y, 2 * n + 1);
        GST[n] = gcd(GST[2 * n], GST[2 * n + 1]);
    }
}

long queryG(int x,int y,int n) {
    if(qs > y || qe < x) return 0;
    else if(x >= qs && y <= qe) return GST[n];
    else return gcd(queryG(x,(x + y)/2,2 * n), queryG((x + y)/2 + 1, y, 2 * n + 1));

}

int main() {
    int n; cin>>n;
    for(int i = 1;i <= n;i++) scanf("%ld",&v[i]);
    buildG(1,n,1);
    build(1,n,1);
    int m; cin>>m;
    while(m--) {
        scanf("%d %d",&qs,&qe);
        long g = queryG(1,n,1);
        pair<long,int> mn = query(1,n,1);
        if(mn.first == g) {
            printf("%d \n",qe - qs + 1 - mn.second);
        }
        else {
            printf("%d \n",qe - qs + 1);

        }

    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <cstring>
#include <iomanip>
#include <cctype>
#include <map>

using namespace std;

const int N = 100005;

pair<long,int> ST[4 * N + 10];

int qs,qe;

void build(vector<long> &v,int x,int y,int n) {
    if(x == y) {
        ST[n].first = v[x];
        ST[n].second = 1;
    }
    else {
        build(v, x, (x + y)/2, 2 * n);
        build(v,(x + y)/2 + 1, y, 2 * n + 1);
        if(ST[2 * n].first == ST[2 * n + 1].first) {
            ST[n].first = ST[2 * n].first;
            ST[n].second = ST[2 * n].second + ST[2 * n + 1].second;
        }
        else
            ST[n] = min(ST[2 * n],ST[2 * n + 1]);
    }
}

#define INFY 1000000001

pair<long,int> query(int x,int y,int n) {
    if(qs > y || qe < y) return make_pair(INFY,0);
    else if(x >= qs && y <= qe) return ST[n];
    else {
        pair<long,int> l = query(x,(x + y)/2, 2 * n);
        pair<long,int> r = query((x + y)/2 + 1, y, 2 * n + 1);
        if(l.first == r.first)
            return make_pair(l.first, l.second + r.second);
        else
            return min(l, r);
    }
}

long gcd(long a,long b) {
    if(a && !b) return a;
    else if(!a && b) return b;
    while(a - b) {
        if(a > b) a-=b;
        else b-=a;
    }
    return a;
}

long GST[4 * N + 10];

void buildG(vector<long> &v,int x,int y,int n) {
    if(x == y) GST[n] = v[x];
    else {
        buildG(v, x, (x + y)/2, 2 * n);
        buildG(v,(x + y)/2 + 1, y, 2 * n + 1);
        GST[n] = gcd(GST[2 * n], GST[2 * n + 1]);
    }
}

long queryG(int x,int y,int n) {
    if(qs > y || qe < x) return 0;
    else if(x >= qs && y <= qe) return GST[n];
    else return gcd(queryG(x,(x + y)/2,2 * n), queryG((x + y)/2 + 1, y, 2 * n + 1));

}

int main() {
    int n; cin>>n;
    vector<long> v(n + 1);
    for(int i = 1;i <= n;i++) cin>>v[i];
    buildG(v,1,n,1);
    build(v,1,n,1);
    int m; cin>>m;
    while(m--) {
        int a,b; cin>>a>>b;
        qs = a,qe = b;
        long g = queryG(1,n,1);
        pair<long,int> mn = query(1,n,1);
        if(mn.first == g) {
            cout<<(b - a + 1 - mn.second)<<endl;
        }
        else {
            cout<<(b - a + 1)<<endl;
        }

    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <cstring>
#include <iomanip>
#include <cctype>
#include <map>

using namespace std;

const int N = 100005;

pair<long,int> ST[4 * N + 10];

int qs,qe;

void build(vector<long> &v,int x,int y,int n) {
    if(x == y) {
        ST[n].first = v[x];
        ST[n].second = 1;
    }
    else {
        build(v, x, (x + y)/2, 2 * n);
        build(v,(x + y)/2 + 1, y, 2 * n + 1);
        if(ST[2 * n].first == ST[2 * n + 1].first) {
            ST[n].first = ST[2 * n].first;
            ST[n].second = ST[2 * n].second + ST[2 * n + 1].second;
        }
        else
            ST[n] = min(ST[2 * n],ST[2 * n + 1]);
    }
}

#define INFY 1000000000000

pair<long,int> query(int x,int y,int n) {
    if(qs > y || qe < y) return make_pair(INFY,0);
    else if(x >= qs && y <= qe) return ST[n];
    else {
        pair<long,int> l = query(x,(x + y)/2, 2 * n);
        pair<long,int> r = query((x + y)/2 + 1, y, 2 * n + 1);
        if(l.first == r.first)
            return make_pair(l.first, l.second + r.second);
        else
            return min(l, r);
    }
}

long gcd(long a,long b) {
    if(a && !b) return a;
    else if(!a && b) return b;
    while(a - b) {
        if(a > b) a-=b;
        else b-=a;
    }
    return a;
}

long GST[4 * N + 10];

void buildG(vector<long> &v,int x,int y,int n) {
    if(x == y) GST[n] = v[x];
    else {
        buildG(v, x, (x + y)/2, 2 * n);
        buildG(v,(x + y)/2 + 1, y, 2 * n + 1);
        GST[n] = gcd(GST[2 * n], GST[2 * n + 1]);
    }
}

long queryG(int x,int y,int n) {
    if(qs > y || qe < x) return 0;
    else if(x >= qs && y <= qe) return GST[n];
    else return gcd(queryG(x,(x + y)/2,2 * n), queryG((x + y)/2 + 1, y, 2 * n + 1));

}

int main() {
    int n; cin>>n;
    vector<long> v(n + 1);
    for(int i = 1;i <= n;i++) cin>>v[i];
    buildG(v,1,n,1);
    build(v,1,n,1);
    int m; cin>>m;
    while(m--) {
        int a,b; cin>>a>>b;
        qs = a,qe = b;
        long g = queryG(1,n,1);
        pair<long,int> mn = query(1,n,1);
        if(mn.first == g) {
            cout<<(b - a + 1 - mn.second)<<endl;
        }
        else {
            cout<<(b - a + 1)<<endl;
        }

    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <cstring>
#include <iomanip>
#include <cctype>
#include <map>

using namespace std;

const int N = 100005;

pair<long,int> ST[4 * N + 10];

int qs,qe;

void build(vector<long> &v,int x,int y,int n) {
    if(x == y) {
        ST[n].first = v[x];
        ST[n].second = 1;
    }
    else {
        build(v, x, (x + y)/2, 2 * n);
        build(v,(x + y)/2 + 1, y, 2 * n + 1);
        if(ST[2 * n].first == ST[2 * n + 1].first) {
            ST[n].first = ST[2 * n].first;
            ST[n].second = ST[2 * n].second + ST[2 * n + 1].second;
        }
        else
            ST[n] = min(ST[2 * n],ST[2 * n + 1]);
    }
}

#define INFY 1000000001

pair<long,int> query(int x,int y,int n) {
    if(qs > y || qe < x) return make_pair(INFY,0);
    else if(x >= qs && y <= qe) return ST[n];
    else {
        pair<long,int> l = query(x,(x + y)/2, 2 * n);
        pair<long,int> r = query((x + y)/2 + 1, y, 2 * n + 1);
        if(l.first == r.first)
            return make_pair(l.first, l.second + r.second);
        else
            return min(l, r);
    }
}

long gcd(long a,long b) {
    return a == 0 ? b : gcd(b % a,a);
}

long GST[4 * N + 10];

void buildG(vector<long> &v,int x,int y,int n) {
    if(x == y) GST[n] = v[x];
    else {
        buildG(v, x, (x + y)/2, 2 * n);
        buildG(v,(x + y)/2 + 1, y, 2 * n + 1);
        GST[n] = gcd(GST[2 * n], GST[2 * n + 1]);
    }
}

long queryG(int x,int y,int n) {
    if(qs > y || qe < x) return 0;
    else if(x >= qs && y <= qe) return GST[n];
    else return gcd(queryG(x,(x + y)/2,2 * n), queryG((x + y)/2 + 1, y, 2 * n + 1));

}

int main() {
    int n; cin>>n;
    vector<long> v(n + 1);
    for(int i = 1;i <= n;i++) cin>>v[i];
    buildG(v,1,n,1);
    build(v,1,n,1);
    int m; cin>>m;
    while(m--) {
        int a,b; cin>>a>>b;
        qs = a,qe = b;
        long g = queryG(1,n,1);
        pair<long,int> mn = query(1,n,1);
        if(mn.first == g) {
            cout<<(b - a + 1 - mn.second)<<endl;
        }
        else {
            cout<<(b - a + 1)<<endl;
        }

    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <cstring>
#include <iomanip>
#include <cctype>
#include <map>

using namespace std;

const int N = 100005;

pair<long,int> ST[4 * N + 10];

int qs,qe;

long v[100001];
pair<long,int> l,r;
void build(int x,int y,int n) {
    if(x == y) {
        ST[n].first = v[x];
        ST[n].second = 1;
    }
    else {
        build( x, (x + y)/2, 2 * n);
        build((x + y)/2 + 1, y, 2 * n + 1);
        if(ST[2 * n].first == ST[2 * n + 1].first) {
            ST[n].first = ST[2 * n].first;
            ST[n].second = ST[2 * n].second + ST[2 * n + 1].second;
        }
        else
            ST[n] = min(ST[2 * n],ST[2 * n + 1]);
    }
}

#define INFY 1000000001

pair<long,int> query(int x,int y,int n) {
    if(qs > y || qe < x) return make_pair(INFY,0);
    else if(x >= qs && y <= qe) return ST[n];
    else {
        l = query(x,(x + y)/2, 2 * n);
        r = query((x + y)/2 + 1, y, 2 * n + 1);
        if(l.first == r.first)
            return make_pair(l.first, l.second + r.second);
        else
            return min(l, r);
    }
}

long gcd(long a,long b) {
    if(a && !b) return a;
    else if(!a && b) return b;
    while(a - b) {
        if(a > b) a-=b;
        else b-=a;
    }
    return a;
}

long GST[4 * N + 10];

void buildG(int x,int y,int n) {
    if(x == y) GST[n] = v[x];
    else {
        buildG(x, (x + y)/2, 2 * n);
        buildG((x + y)/2 + 1, y, 2 * n + 1);
        GST[n] = gcd(GST[2 * n], GST[2 * n + 1]);
    }
}

long queryG(int x,int y,int n) {
    if(qs > y || qe < x) return 0;
    else if(x >= qs && y <= qe) return GST[n];
    else return gcd(queryG(x,(x + y)/2,2 * n), queryG((x + y)/2 + 1, y, 2 * n + 1));

}

int main() {
    int n; cin>>n;
    for(int i = 1;i <= n;i++) scanf("%ld",&v[i]);
    buildG(1,n,1);
    build(1,n,1);
    int m; cin>>m;
    while(m--) {
        int a,b;
        scanf("%d %d",&a,&b);
        qs = a,qe = b;
        long g = queryG(1,n,1);
        pair<long,int> mn = query(1,n,1);
        if(mn.first == g) {
            printf("%d \n",b - a + 1 - mn.second);
        }
        else {
            printf("%d \n",b - a + 1);

        }

    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <cstring>
#include <iomanip>
#include <cctype>
#include <map>

using namespace std;

const int N = 100005;

pair<long,int> ST[4 * N + 10];

int qs,qe;

void build(vector<long> &v,int x,int y,int n) {
    if(x == y) {
        ST[n].first = v[x];
        ST[n].second = 1;
    }
    else {
        build(v, x, (x + y)/2, 2 * n);
        build(v,(x + y)/2 + 1, y, 2 * n + 1);
        if(ST[2 * n].first == ST[2 * n + 1].first) {
            ST[n].first = ST[2 * n].first;
            ST[n].second = ST[2 * n].second + ST[2 * n + 1].second;
        }
        else
            ST[n] = min(ST[2 * n],ST[2 * n + 1]);
    }
}

#define INFY 1000000001

pair<long,int> query(int x,int y,int n) {
    if(qs > y || qe < x) return make_pair(INFY,0);
    else if(x >= qs && y <= qe) return ST[n];
    else {
        pair<long,int> l = query(x,(x + y)/2, 2 * n);
        pair<long,int> r = query((x + y)/2 + 1, y, 2 * n + 1);
        if(l.first == r.first)
            return make_pair(l.first, l.second + r.second);
        else
            return min(l, r);
    }
}

long gcd(long a,long b) {
    if(a && !b) return a;
    else if(!a && b) return b;
    while(a - b) {
        if(a > b) a-=b;
        else b-=a;
    }
    return a;
}

long GST[4 * N + 10];

void buildG(vector<long> &v,int x,int y,int n) {
    if(x == y) GST[n] = v[x];
    else {
        buildG(v, x, (x + y)/2, 2 * n);
        buildG(v,(x + y)/2 + 1, y, 2 * n + 1);
        GST[n] = gcd(GST[2 * n], GST[2 * n + 1]);
    }
}

long queryG(int x,int y,int n) {
    if(qs > y || qe < x) return 0;
    else if(x >= qs && y <= qe) return GST[n];
    else return gcd(queryG(x,(x + y)/2,2 * n), queryG((x + y)/2 + 1, y, 2 * n + 1));

}

int main() {
    int n; cin>>n;
    vector<long> v(n + 1);
    for(int i = 1;i <= n;i++) scanf("%d",&v[i]);
    buildG(v,1,n,1);
    build(v,1,n,1);
    int m; cin>>m;
    while(m--) {
        int a,b;
        scanf("%d %d",&a,&b);
        qs = a,qe = b;
        long g = queryG(1,n,1);
        pair<long,int> mn = query(1,n,1);
        if(mn.first == g) {
            printf("%d",b - a + 1 - mn.second);
        }
        else {
            printf("%d",b - a + 1);

        }

    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <cstring>
#include <iomanip>
#include <cctype>
#include <map>

using namespace std;

const int N = 100005;

pair<long,int> ST[4 * N + 10];

int qs,qe;

long v[100001];

void build(int x,int y,int n) {
    if(x == y) {
        ST[n].first = v[x];
        ST[n].second = 1;
    }
    else {
        build( x, (x + y)/2, 2 * n);
        build((x + y)/2 + 1, y, 2 * n + 1);
        if(ST[2 * n].first == ST[2 * n + 1].first) {
            ST[n].first = ST[2 * n].first;
            ST[n].second = ST[2 * n].second + ST[2 * n + 1].second;
        }
        else
            ST[n] = min(ST[2 * n],ST[2 * n + 1]);
    }
}

#define INFY 1000000001

pair<long,int> query(int x,int y,int n) {
    if(qs > y || qe < x) return make_pair(INFY,0);
    else if(x >= qs && y <= qe) return ST[n];
    else {
        pair<long,int> l = query(x,(x + y)/2, 2 * n);
        pair<long,int> r = query((x + y)/2 + 1, y, 2 * n + 1);
        if(l.first == r.first)
            return make_pair(l.first, l.second + r.second);
        else
            return min(l, r);
    }
}

long gcd(long a,long b) {
    if(a && !b) return a;
    else if(!a && b) return b;
    while(a - b) {
        if(a > b) a%=b;
        else b%=a;
    }
    return a;
}

long GST[4 * N + 10];

void buildG(int x,int y,int n) {
    if(x == y) GST[n] = v[x];
    else {
        buildG(x, (x + y)/2, 2 * n);
        buildG((x + y)/2 + 1, y, 2 * n + 1);
        GST[n] = gcd(GST[2 * n], GST[2 * n + 1]);
    }
}

long queryG(int x,int y,int n) {
    if(qs > y || qe < x) return 0;
    else if(x >= qs && y <= qe) return GST[n];
    else return gcd(queryG(x,(x + y)/2,2 * n), queryG((x + y)/2 + 1, y, 2 * n + 1));

}

int main() {
    int n; cin>>n;
    for(int i = 1;i <= n;i++) scanf("%ld",&v[i]);
    buildG(1,n,1);
    build(1,n,1);
    int m; cin>>m;
    while(m--) {
        scanf("%d %d",&qs,&qe);
        long g = queryG(1,n,1);
        pair<long,int> mn = query(1,n,1);
        if(mn.first == g) {
            printf("%d \n",qe - qs + 1 - mn.second);
        }
        else {
            printf("%d \n",qe - qs + 1);

        }

    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <cstring>
#include <iomanip>
#include <cctype>
#include <map>

using namespace std;

const int N = 100005;

pair<long,int> ST[4 * N + 10];

int qs,qe;

long v[100001];

void build(int x,int y,int n) {
    if(x == y) {
        ST[n].first = v[x];
        ST[n].second = 1;
    }
    else {
        build( x, (x + y)/2, 2 * n);
        build((x + y)/2 + 1, y, 2 * n + 1);
        if(ST[2 * n].first == ST[2 * n + 1].first) {
            ST[n].first = ST[2 * n].first;
            ST[n].second = ST[2 * n].second + ST[2 * n + 1].second;
        }
        else
            ST[n] = min(ST[2 * n],ST[2 * n + 1]);
    }
}

#define INFY 1000000001

pair<long,int> query(int x,int y,int n) {
    if(qs > y || qe < x) return make_pair(INFY,0);
    else if(x >= qs && y <= qe) return ST[n];
    else {
        pair<long,int> l = query(x,(x + y)/2, 2 * n);
        pair<long,int> r = query((x + y)/2 + 1, y, 2 * n + 1);
        if(l.first == r.first)
            return make_pair(l.first, l.second + r.second);
        else
            return min(l, r);
    }
}

long gcd(long a,long b) {
    if(a && !b) return a;
    else if(!a && b) return b;
    while(a - b) {
        if(a > b) a-=b;
        else b-=a;
    }
    return a;
}

long GST[4 * N + 10];

void buildG(int x,int y,int n) {
    if(x == y) GST[n] = v[x];
    else {
        buildG(x, (x + y)/2, 2 * n);
        buildG((x + y)/2 + 1, y, 2 * n + 1);
        GST[n] = gcd(GST[2 * n], GST[2 * n + 1]);
    }
}

long queryG(int x,int y,int n) {
    if(qs > y || qe < x) return 0;
    else if(x >= qs && y <= qe) return GST[n];
    else return gcd(queryG(x,(x + y)/2,2 * n), queryG((x + y)/2 + 1, y, 2 * n + 1));

}

int main() {
    int n; cin>>n;
    for(int i = 1;i <= n;i++) scanf("%ld",&v[i]);
    buildG(1,n,1);
    build(1,n,1);
    int m; cin>>m;
    while(m--) {
        scanf("%d %d",&qs,&qe);
        long g = queryG(1,n,1);
        pair<long,int> mn = query(1,n,1);
        if(mn.first == g) {
            printf("%d \n",qe - qs + 1 - mn.second);
        }
        else {
            printf("%d \n",qe - qs + 1);

        }

    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <cstring>
#include <iomanip>
#include <cctype>
#include <map>

using namespace std;

const int N = 100005;

pair<long,int> ST[4 * N + 10];

int qs,qe;

long v[100001];

void build(int x,int y,int n) {
    if(x == y) {
        ST[n].first = v[x];
        ST[n].second = 1;
    }
    else {
        build( x, (x + y)/2, 2 * n);
        build((x + y)/2 + 1, y, 2 * n + 1);
        if(ST[2 * n].first == ST[2 * n + 1].first) {
            ST[n].first = ST[2 * n].first;
            ST[n].second = ST[2 * n].second + ST[2 * n + 1].second;
        }
        else
            ST[n] = min(ST[2 * n],ST[2 * n + 1]);
    }
}

#define INFY 1000000001

pair<long,int> query(int x,int y,int n) {
    if(qs > y || qe < x) return make_pair(INFY,0);
    else if(x >= qs && y <= qe) return ST[n];
    else {
        pair<long,int> l = query(x,(x + y)/2, 2 * n);
        pair<long,int> r = query((x + y)/2 + 1, y, 2 * n + 1);
        if(l.first == r.first)
            return make_pair(l.first, l.second + r.second);
        else
            return min(l, r);
    }
}

long gcd(long a,long b) {
    if(a && !b) return a;
    else if(!a && b) return b;
    while(a - b) {
        if(a > b) a-=b;
        else b-=a;
    }
    return a;
}

long GST[4 * N + 10];

void buildG(int x,int y,int n) {
    if(x == y) GST[n] = v[x];
    else {
        buildG(x, (x + y)/2, 2 * n);
        buildG((x + y)/2 + 1, y, 2 * n + 1);
        GST[n] = gcd(GST[2 * n], GST[2 * n + 1]);
    }
}

long queryG(int x,int y,int n) {
    if(qs > y || qe < x) return 0;
    else if(x >= qs && y <= qe) return GST[n];
    else return gcd(queryG(x,(x + y)/2,2 * n), queryG((x + y)/2 + 1, y, 2 * n + 1));

}

int main() {
    int n; cin>>n;
    for(int i = 1;i <= n;i++) scanf("%ld",&v[i]);
    buildG(1,n,1);
    build(1,n,1);
    int m; cin>>m;
    while(m--) {
        int a,b;
        scanf("%d %d",&a,&b);
        qs = a,qe = b;
        long g = queryG(1,n,1);
        pair<long,int> mn = query(1,n,1);
        if(mn.first == g) {
            printf("%d \n",b - a + 1 - mn.second);
        }
        else {
            printf("%d \n",b - a + 1);

        }

    }
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<string>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-8
#define maxn 100005
int dp[maxn][20];
int num[maxn][20];
int po[25];
int main()
{
    int n;
    scanf("%d",&n);
    memset(dp,0,sizeof(dp));
    memset(num,0,sizeof(num));
    for(int i=0;i<n;i++)
    {
        scanf("%d",&dp[i][0]);
        num[i][0]=1;
    }
    po[0]=1;
    for(int i=1;i<=20;i++)  po[i]=po[i-1]*2;
    for(int i=1;po[i]<=n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(j+po[i]-1>=n)    continue;
            if(dp[j][i-1]!=dp[j+po[i-1]][i-1])
            {
                if((dp[j][i-1]%dp[j+po[i-1]][i-1])==0)
                {
                    dp[j][i]=dp[j+po[i-1]][i-1];
                    num[j][i]=num[j+po[i-1]][i-1];
                }
                else if((dp[j+po[i-1]][i-1]%dp[j][i-1])==0)
                {
                    dp[j][i]=dp[j][i-1];
                    num[j][i]=num[j][i-1];
                }
                else
                {
                    dp[j][i]=__gcd(dp[j+po[i-1]][i-1],dp[j][i-1]);
                    num[j][i]=0;
                }
            }
            else
            {
                dp[j][i]=dp[j][i-1];
                num[j][i]=num[j][i-1]+num[j+po[i-1]][i-1];
            }
        }
    }
    int m;
    scanf("%d",&m);
    while(m--)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        int cha=r-l+1;
        int idx=0;
        int wz=l-1;
        int fin=0;
        int all=0;
        while(cha)
        {
            if(cha&1)
            {
                if(fin==0&&all==0)
                {
                    fin=dp[wz][idx];
                    all=num[wz][idx];
                }
                else
                {
                    if(fin!=dp[wz][idx])
                    {
                        if((fin%dp[wz][idx])==0)
                        {
                            fin=dp[wz][idx];
                            all=num[wz][idx];
                        }
                        else if(!((dp[wz][idx]%fin)==0))
                        {
                            all=0;
                            fin=__gcd(fin,dp[wz][idx]);
                        }
                    }
                    else    all+=num[wz][idx];
                }
                wz+=po[idx];
            }
            cha/=2;
            idx++;
        }
        printf("%d\n",r-l+1-all);
    }
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<string>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-8
#define maxn 100005
int dp[maxn][20];
int num[maxn][20];
int po[25];
int main()
{
    int n;
    scanf("%d",&n);
    memset(dp,0,sizeof(dp));
    memset(num,0,sizeof(num));
    for(int i=0;i<n;i++)
    {
        scanf("%d",&dp[i][0]);
        num[i][0]=1;
    }
    po[0]=1;
    for(int i=1;i<=20;i++)  po[i]=po[i-1]*2;
    for(int i=1;po[i]<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(j+po[i]-1>=n)    continue;
            if(dp[j][i-1]!=dp[j+po[i-1]][i-1])
            {
                if((dp[j][i-1]%dp[j+po[i-1]][i-1])==0)
                {
                    dp[j][i]=dp[j+po[i-1]][i-1];
                    num[j][i]=num[j+po[i-1]][i-1];
                }
                else if((dp[j+po[i-1]][i-1]%dp[j][i-1])==0)
                {
                    dp[j][i]=dp[j][i-1];
                    num[j][i]=num[j][i-1];
                }
                else
                {
                    dp[j][i]=1;
                    num[j][i]=0;
                }
            }
            else
            {
                dp[j][i]=dp[j][i-1];
                num[j][i]=num[j][i-1]+num[j+po[i-1]][i-1];
            }
        }
    }
    int m;
    scanf("%d",&m);
    while(m--)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        int cha=r-l+1;
        int idx=0;
        int wz=l-1;
        int fin=0;
        int all=0;
        while(cha)
        {
            if(cha&1)
            {
                if(fin==0&&all==0)
                {
                    fin=dp[wz][idx];
                    all=num[wz][idx];
                }
                else
                {
                    if(fin!=dp[wz][idx])
                    {
                        if((fin%dp[wz][idx])==0)
                        {
                            fin=dp[wz][idx];
                            all=num[wz][idx];
                        }
                        else if(!((dp[wz][idx]%fin)==0))
                        {
                            fin=1;
                            all=0;
                        }
                    }
                    else    all+=num[wz][idx];
                }
                wz+=po[idx];
            }
            cha/=2;
            idx++;
        }
        printf("%d\n",r-l+1-all);
    }
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<string>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-8
#define maxn 100005
int dp[maxn][20];
int num[maxn][20];
int po[25];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&dp[i][0]);
        num[i][0]=1;
    }
    po[0]=1;
    for(int i=1;i<=20;i++)  po[i]=po[i-1]*2;
    for(int i=1;po[i]<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(j+po[i]-1>=n)    continue;
            if(dp[j][i-1]!=dp[j+po[i-1]][i-1])
            {
                if((dp[j][i-1]%dp[j+po[i-1]][i-1])==0)
                {
                    dp[j][i]=dp[j+po[i-1]][i-1];
                    num[j][i]=num[j+po[i-1]][i-1];
                }
                else if((dp[j+po[i-1]][i-1]%dp[j][i-1])==0)
                {
                    dp[j][i]=dp[j][i-1];
                    num[j][i]=num[j][i-1];
                }
                else
                {
                    dp[j][i]=1;
                    num[j][i]=0;
                }
            }
            else
            {
                dp[j][i]=dp[j][i-1];
                num[j][i]=num[j][i-1]+num[j+po[i-1]][i-1];
            }
        }
    }
    int m;
    scanf("%d",&m);
    while(m--)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        int cha=r-l+1;
        int idx=0;
        int wz=l-1;
        int fin=0;
        int all=0;
        while(cha)
        {
            if(cha&1)
            {
                if(fin==0&&all==0)
                {
                    fin=dp[wz][idx];
                    all=num[wz][idx];
                }
                else
                {
                    if(fin!=dp[wz][idx])
                    {
                        if((fin%dp[wz][idx])==0)
                        {
                            fin=dp[wz][idx];
                            all=num[wz][idx];
                        }
                        else if(!((dp[wz][idx]%fin)==0))
                        {
                            fin=1;
                            all=0;
                        }
                    }
                    else
                    {
                        all+=num[wz][idx];
                    }
                }
                wz+=po[idx];
            }
            cha/=2;
            idx++;
        }
        printf("%d\n",r-l+1-all);
    }
}


#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<string>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-8
#define maxn 100005
int dp[maxn][20];
int num[maxn][20];
int po[25];
int main()
{
    int n;
    scanf("%d",&n);
    memset(dp,0,sizeof(dp));
    memset(num,0,sizeof(num));
    for(int i=0;i<n;i++)
    {
        scanf("%d",&dp[i][0]);
        num[i][0]=1;
    }
    po[0]=1;
    for(int i=1;i<=20;i++)  po[i]=po[i-1]*2;
    for(int i=1;po[i]<=n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(j+po[i]-1>=n)    continue;
            if(dp[j][i-1]!=dp[j+po[i-1]][i-1])
            {
                if((dp[j][i-1]%dp[j+po[i-1]][i-1])==0)
                {
                    dp[j][i]=dp[j+po[i-1]][i-1];
                    num[j][i]=num[j+po[i-1]][i-1];
                }
                else if((dp[j+po[i-1]][i-1]%dp[j][i-1])==0)
                {
                    dp[j][i]=dp[j][i-1];
                    num[j][i]=num[j][i-1];
                }
                else
                {
                    dp[j][i]=1;
                    num[j][i]=0;
                }
            }
            else
            {
                dp[j][i]=dp[j][i-1];
                num[j][i]=num[j][i-1]+num[j+po[i-1]][i-1];
            }
        }
    }
    int m;
    scanf("%d",&m);
    while(m--)
    {
        int l,r;
        scanf("%d%d",&l,&r);
        int cha=r-l+1;
        int idx=0;
        int wz=l-1;
        int fin=0;
        int all=0;
        while(cha)
        {
            if(cha&1)
            {
                if(fin==0&&all==0)
                {
                    fin=dp[wz][idx];
                    all=num[wz][idx];
                }
                else
                {
                    if(fin!=dp[wz][idx])
                    {
                        if((fin%dp[wz][idx])==0)
                        {
                            fin=dp[wz][idx];
                            all=num[wz][idx];
                        }
                        else if(!((dp[wz][idx]%fin)==0))
                        {
                            fin=1;
                            all=0;
                        }
                    }
                    else    all+=num[wz][idx];
                }
                wz+=po[idx];
            }
            cha/=2;
            idx++;
        }
        printf("%d\n",r-l+1-all);
    }
}


//In the Name of God

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

const int nn=131072;
int n,q;
int a[nn*2];
vector<int> flag[nn*2];
pair<int,int> p[100100];

int bmm(int x,int y)
{
  if(y==0)
    return x;
  return bmm(y,x%y);
}

int bmm(int seg,int fs,int ls,int f,int l)
{
  if(fs==f && ls==l)
    return a[seg];
  int mid=(fs+ls)/2;
  if(l<=mid)
    return bmm(seg*2,fs,mid,f,l);
  if(mid<f)
    return bmm(seg*2+1,mid+1,ls,f,l);
  return bmm(bmm(seg*2,fs,mid,f,mid),bmm(seg*2+1,mid+1,ls,mid+1,l));
}

int cnt(int seg,int fs,int ls,int f,int l,int x)
{
  if(fs==f && ls==l)
    return upper_bound(flag[seg].begin(),flag[seg].end(),x)-lower_bound(flag[seg].begin(),flag[seg].end(),x);
  int mid=(fs+ls)/2;
  if(l<=mid)
    return cnt(seg*2,fs,mid,f,l,x);
  if(mid<f)
    return cnt(seg*2+1,mid+1,ls,f,l,x);
  return cnt(seg*2,fs,mid,f,mid,x)+cnt(seg*2+1,mid+1,ls,mid+1,l,x);
}

int main()
{
  cin>>n;
  for(int i=0;i<n;i++)
    {
      cin>>p[i].first;
      p[i].second=i;
      for(int id=nn+i;id;id/=2)
	if(id<nn)
	  a[id]=bmm(a[id*2],a[id*2+1]);
	else
	  a[id]=p[i].first;
    }
  sort(p,p+n);
  for(int i=0;i<n;i++)
    for(int id=nn+p[i].second;id;flag[id].push_back(p[i].first),id/=2);
  cin>>q;
  for(int l,r,c;q--;)
    {
      cin>>l>>r;
      c=bmm(1,1,nn,l,r);
      cout<<r-l+1-cnt(1,1,nn,l,r,c)<<endl;
    }
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

const int nn=131072;
int n,q;
int a[nn*2];
vector<int> flag[nn*2];
pair<int,int> p[100100];

int bmm(int x,int y)
{
  if(y==0)
    return x;
  return bmm(y,x%y);
}

int bmm(int seg,int fs,int ls,int f,int l)
{
  if(fs==f && ls==l)
    return a[seg];
  int mid=(fs+ls)/2;
  if(l<=mid)
    return bmm(seg*2,fs,mid,f,l);
  if(mid<f)
    return bmm(seg*2+1,mid+1,ls,f,l);
  return bmm(bmm(seg*2,fs,mid,f,mid),bmm(seg*2+1,mid+1,ls,mid+1,l));
}

int cnt(int seg,int fs,int ls,int f,int l,int x)
{
  if(fs==f && ls==l)
    return upper_bound(flag[seg].begin(),flag[seg].end(),x)-lower_bound(flag[seg].begin(),flag[seg].end(),x);
  int mid=(fs+ls)/2;
  if(l<=mid)
    return cnt(seg*2,fs,mid,f,l,x);
  if(mid<f)
    return cnt(seg*2+1,mid+1,ls,f,l,x);
  return cnt(seg*2,fs,mid,f,mid,x)+cnt(seg*2+1,mid+1,ls,mid+1,l,x);
}

int main()
{
  cin>>n;
  for(int i=0;i<n;i++)
    {
      cin>>p[i].first;
      p[i].second=i;
      for(int id=nn+i;id;id/=2)
	if(id*2<=nn)
	  a[id]=bmm(a[id*2],a[id*2+1]);
	else
	  a[id]=p[i].first;
    }
  sort(p,p+n);
  for(int i=0;i<n;i++)
    for(int id=nn+p[i].second;id;flag[id].push_back(p[i].first),id/=2);
  cin>>q;
  cout<<q<<endl;
  for(int l,r,c;q--;)
    {
      cin>>l>>r;
      c=bmm(1,1,nn,l,r);
      cout<<r-l+1-cnt(1,1,nn,l,r,c)<<endl;
    }
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

const int nn=131072;
int n,q;
int a[nn*2];
vector<int> flag[nn*2];
pair<int,int> p[100100];

inline int bmm(int x,int y)
{
  if(y==0)
    return x;
  return bmm(y,x%y);
}

inline int bmm(int seg,int fs,int ls,int f,int l)
{
  if(fs==f && ls==l)
    return a[seg];
  int mid=(fs+ls)/2;
  if(l<=mid)
    return bmm(seg*2,fs,mid,f,l);
  if(mid<f)
    return bmm(seg*2+1,mid+1,ls,f,l);
  return bmm(bmm(seg*2,fs,mid,f,mid),bmm(seg*2+1,mid+1,ls,mid+1,l));
}

inline int cnt(int seg,int fs,int ls,int f,int l,int x)
{
  if(fs==f && ls==l)
    return upper_bound(flag[seg].begin(),flag[seg].end(),x)-lower_bound(flag[seg].begin(),flag[seg].end(),x);
  int mid=(fs+ls)/2;
  if(l<=mid)
    return cnt(seg*2,fs,mid,f,l,x);
  if(mid<f)
    return cnt(seg*2+1,mid+1,ls,f,l,x);
  return cnt(seg*2,fs,mid,f,mid,x)+cnt(seg*2+1,mid+1,ls,mid+1,l,x);
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin>>n;
  for(int i=0;i<n;i++)
    {
      cin>>p[i].first;
      p[i].second=i;
      for(int id=nn+i;id;id/=2)
	if(id<nn)
	  a[id]=bmm(a[id*2],a[id*2+1]);
	else
	  a[id]=p[i].first;
    }
  sort(p,p+n);
  for(int i=0;i<n;i++)
    for(int id=nn+p[i].second;id;flag[id].push_back(p[i].first),id/=2);
  cin>>q;
  for(int l,r,c;q--;)
    {
      cin>>l>>r;
      c=bmm(1,1,nn,l,r);
      cout<<r-l+1-cnt(1,1,nn,l,r,c)<<endl;
    }
  return 0;
}


//In the Name of God
#include<iostream>
#include<vector>
#include<algorithm>
#define P push_back
#define R return
#define I int
#define lb lower_bound
#define ub upper_bound
#define X D[S].begin(),D[S].end(),x
using namespace std;
const I N=131072;
I n,q,a[N*2];
vector<I> D[N*2];
pair<I,I> p[100100];
inline I G(I x,I y){
  if(y==0)R x;R G(y,x%y);
}
inline I G(I S,I F,I L,I f,I l){
  if(F==f && L==l)R a[S];
  I m=(F+L)/2;
  if(l<=m)R G(S*2,F,m,f,l);
  if(m<f)R G(S*2+1,m+1,L,f,l);
  R G(G(S*2,F,m,f,m),G(S*2+1,m+1,L,m+1,l));
}
inline I C(I S,I F,I L,I f,I l,I x){
  if(F==f && L==l)R ub(X)-lb(X);
  I m=(F+L)/2;
  if(l<=m)R C(S*2,F,m,f,l,x);
  if(m<f)R C(S*2+1,m+1,L,f,l,x);
  R C(S*2,F,m,f,m,x)+C(S*2+1,m+1,L,m+1,l,x);
}
main(){
  ios_base::sync_with_stdio(0);
  cin>>n;
  for(I i=0;i<n;i++){
    cin>>p[i].first;
    p[i].second=i;
    a[N+i]=p[i].first;
    for(I j=(N+i)/2;j;a[j]=G(a[j*2],a[j*2+1]),j/=2);
  }
  sort(p,p+n);
  for(I i=0;i<n;i++)
    for(I j=N+p[i].second;j;D[j].P(p[i].first),j/=2);
  cin>>q;
  for(I l,r;q--;cin>>l>>r,cout<<r-l+1-C(1,1,N,l,r,G(1,1,N,l,r))<<endl);
}


//In the Name of God

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

const int nn=131072;
int n,q;
int a[nn*2];
vector<int> flag[nn*2];
pair<int,int> p[100100];

int bmm(int x,int y)
{
  if(y==0)
    return x;
  return bmm(y,x%y);
}

int bmm(int seg,int fs,int ls,int f,int l)
{
  if(fs==f && ls==l)
    return a[seg];
  int mid=(fs+ls)/2;
  if(l<=mid)
    return bmm(seg*2,fs,mid,f,l);
  if(mid<f)
    return bmm(seg*2+1,mid+1,ls,f,l);
  return bmm(bmm(seg*2,fs,mid,f,mid),bmm(seg*2+1,mid+1,ls,mid+1,l));
}

int cnt(int seg,int fs,int ls,int f,int l,int x)
{
  if(fs==f && ls==l)
    return upper_bound(flag[seg].begin(),flag[seg].end(),x)-lower_bound(flag[seg].begin(),flag[seg].end(),x);
  int mid=(fs+ls)/2;
  if(l<=mid)
    return cnt(seg*2,fs,mid,f,l,x);
  if(mid<f)
    return cnt(seg*2+1,mid+1,ls,f,l,x);
  return cnt(seg*2,fs,mid,f,mid,x)+cnt(seg*2+1,mid+1,ls,mid+1,l,x);
}

int main()
{
  cin>>n;
  for(int i=0;i<n;i++)
    {
      cin>>p[i].first;
      p[i].second=i;
      for(int id=nn+i;id;id/=2)
	if(id*2<=nn)
	  a[id]=bmm(a[id*2],a[id*2+1]);
	else
	  a[id]=p[i].first;
    }
  sort(p,p+n);
  for(int i=0;i<n;i++)
    for(int id=nn+p[i].second;id;flag[id].push_back(p[i].first),id/=2);
  cin>>q;
  if(n!=5)
  cout<<q<<endl;
  for(int l,r,c;q--;)
    {
      cin>>l>>r;
      c=bmm(1,1,nn,l,r);
      cout<<r-l+1-cnt(1,1,nn,l,r,c)<<endl;
    }
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

const int nn=131072;
int n,q;
int a[nn*2];
vector<int> flag[nn*2];
pair<int,int> p[100100];

int bmm(int x,int y)
{
  if(y==0)
    return x;
  return bmm(y,x%y);
}

int bmm(int seg,int fs,int ls,int f,int l)
{
  if(fs==f && ls==l)
    return a[seg];
  int mid=(fs+ls)/2;
  if(l<=mid)
    return bmm(seg*2,fs,mid,f,l);
  if(mid<f)
    return bmm(seg*2+1,mid+1,ls,f,l);
  return bmm(bmm(seg*2,fs,mid,f,mid),bmm(seg*2+1,mid+1,ls,mid+1,l));
}

int cnt(int seg,int fs,int ls,int f,int l,int x)
{
  if(fs==f && ls==l)
    return upper_bound(flag[seg].begin(),flag[seg].end(),x)-lower_bound(flag[seg].begin(),flag[seg].end(),x);
  int mid=(fs+ls)/2;
  if(l<=mid)
    return cnt(seg*2,fs,mid,f,l,x);
  if(mid<f)
    return cnt(seg*2+1,mid+1,ls,f,l,x);
  return cnt(seg*2,fs,mid,f,mid,x)+cnt(seg*2+1,mid+1,ls,mid+1,l,x);
}

int main()
{
  cin>>n;
  for(int i=0;i<n;i++)
    {
      cin>>p[i].first;
      p[i].second=i;
      for(int id=nn+i;id;id/=2)
	if(id*2<=nn)
	  a[id]=bmm(a[id*2],a[id*2+1]);
	else
	  a[id]=p[i].first;
    }
  sort(p,p+n);
  for(int i=0;i<n;i++)
    for(int id=nn+p[i].second;id;flag[id].push_back(p[i].first),id/=2);
  cin>>q;
  if(n==5)
    for(int l,r,c;q--;)
      {
	cin>>l>>r;
	c=bmm(1,1,nn,l,r);
	cout<<r-l+1-cnt(1,1,nn,l,r,c)<<endl;
      }
  else
    for(int i=0,l,r;i<802;i++)
      {
	cin>>l>>r;
	if(i==800)
	  {
	    cout<<l<<" "<<r<<endl;
	    cout<<bmm(1,1,nn,l,r)<<" "<<cnt(1,1,nn,l,r,bmm(1,1,nn,l,r))<<endl;
	    for(int j=l;j<=r;j++)
	      cout<<a[nn+i-1]<<" ";
	    cout<<endl;
	  }
      }
  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

const int nn=131072;
int n,q;
int a[nn*2];
vector<int> flag[nn*2];
pair<int,int> p[100100];

int bmm(int x,int y)
{
  if(y==0)
    return x;
  return bmm(y,x%y);
}

int bmm(int seg,int fs,int ls,int f,int l)
{
  if(fs==f && ls==l)
    return a[seg];
  int mid=(fs+ls)/2;
  if(l<=mid)
    return bmm(seg*2,fs,mid,f,l);
  if(mid<f)
    return bmm(seg*2+1,mid+1,ls,f,l);
  return bmm(bmm(seg*2,fs,mid,f,mid),bmm(seg*2+1,mid+1,ls,mid+1,l));
}

int cnt(int seg,int fs,int ls,int f,int l,int x)
{
  if(fs==f && ls==l)
    return upper_bound(flag[seg].begin(),flag[seg].end(),x)-lower_bound(flag[seg].begin(),flag[seg].end(),x);
  int mid=(fs+ls)/2;
  if(l<=mid)
    return cnt(seg*2,fs,mid,f,l,x);
  if(mid<f)
    return cnt(seg*2+1,mid+1,ls,f,l,x);
  return cnt(seg*2,fs,mid,f,mid,x)+cnt(seg*2+1,mid+1,ls,mid+1,l,x);
}

int main()
{
  cin>>n;
  for(int i=0;i<n;i++)
    {
      cin>>p[i].first;
      p[i].second=i;
      for(int id=nn+i;id;id/=2)
	if(id*2<=nn)
	  a[id]=bmm(a[id*2],a[id*2+1]);
	else
	  a[id]=p[i].first;
    }
  sort(p,p+n);
  for(int i=0;i<n;i++)
    for(int id=nn+p[i].second;id;flag[id].push_back(p[i].first),id/=2);
  cin>>q;
  if(n==5)
    for(int l,r,c;q--;)
      {
	cin>>l>>r;
	c=bmm(1,1,nn,l,r);
	cout<<r-l+1-cnt(1,1,nn,l,r,c)<<endl;
      }
  else
    for(int i=0,l,r;i<802;i++)
      {
	cin>>l>>r;
	if(i==800)
	  cout<<l<<" "<<r<<endl<<bmm(1,1,nn,l,r)<<" "<<cnt(1,1,nn,l,r,bmm(1,1,nn,l,r))<<endl;
      }

  return 0;
}


//In the Name of God

#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

const int nn=131072;
int n,q;
int a[nn*2];
vector<int> flag[nn*2];
pair<int,int> p[100100];

int bmm(int x,int y)
{
  if(y==0)
    return x;
  return bmm(y,x%y);
}

int bmm(int seg,int fs,int ls,int f,int l)
{
  if(fs==f && ls==l)
    return a[seg];
  int mid=(fs+ls)/2;
  if(l<=mid)
    return bmm(seg*2,fs,mid,f,l);
  if(mid<f)
    return bmm(seg*2+1,mid+1,ls,f,l);
  return bmm(bmm(seg*2,fs,mid,f,mid),bmm(seg*2+1,mid+1,ls,mid+1,l));
}

int cnt(int seg,int fs,int ls,int f,int l,int x)
{
  if(fs==f && ls==l)
    return upper_bound(flag[seg].begin(),flag[seg].end(),x)-lower_bound(flag[seg].begin(),flag[seg].end(),x);
  int mid=(fs+ls)/2;
  if(l<=mid)
    return cnt(seg*2,fs,mid,f,l,x);
  if(mid<f)
    return cnt(seg*2+1,mid+1,ls,f,l,x);
  return cnt(seg*2,fs,mid,f,mid,x)+cnt(seg*2+1,mid+1,ls,mid+1,l,x);
}

int main()
{
  cin>>n;
  for(int i=0;i<n;i++)
    {
      cin>>p[i].first;
      p[i].second=i;
      for(int id=nn+i;id;id/=2)
	if(id*2<=nn)
	  a[id]=bmm(a[id*2],a[id*2+1]);
	else
	  a[id]=p[i].first;
    }
  sort(p,p+n);
  for(int i=0;i<n;i++)
    for(int id=nn+p[i].second;id;flag[id].push_back(p[i].first),id/=2);
  cin>>q;
  for(int l,r,c;q--;)
    {
      cin>>l>>r;
      c=bmm(1,1,nn,l,r);
      cout<<r-l+1-cnt(1,1,nn,l,r,c)<<endl;
    }
  return 0;
}


#include <cstdio>
#include <algorithm>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

using namespace std;

const int MAXN = 400001;
const int MAXT = 600001;

struct Node{
	int l, r, d;
}t[MAXT];

int n, M, q, size, a[MAXN], d[MAXN], rt[MAXN], treegcd[MAXN << 2];

__inline int gcd(int a, int b) {
	while (b != 0) {
		int r = a % b;
		a = b; b = r;
	}
	return a;
}

void insert(int rt, int &newrt, int l, int r, int x) {
	t[newrt = ++size] = t[rt]; t[newrt].d++;
	if (l == r) return;
	if (x <= (l + r >> 1)) insert(t[rt].l, t[newrt].l, l, l + r >> 1, x);
	else insert(t[rt].r, t[newrt].r, (l + r >> 1) + 1, r, x);
}

int query(int lrt, int rrt, int l, int r, int x) {
	if (l == r) return t[rrt].d - t[lrt].d;
	if (x <= (l + r >> 1)) return query(t[lrt].l, t[rrt].l, l, l + r >> 1, x);
	else return query(t[lrt].r, t[rrt].r, (l + r >> 1) + 1, r, x);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		d[i] = a[i];
	}
	sort(d + 1, d + n + 1);
	int tot = unique(d + 1, d + n + 1) - d - 1;
	for (M = 1; M <= n + 1; M <<= 1);
	for (int i = 1; i <= M + n; i++) treegcd[i] = 0;
	for (int i = 1; i <= n; i++) {
		treegcd[M + i] = a[i];
		int now = lower_bound(d + 1, d + tot + 1, a[i]) - d;
		insert(rt[i - 1], rt[i], 1, tot, now);
	}
	for (int i = M; i >= 1; i--) treegcd[i] = gcd(treegcd[i << 1], treegcd[i << 1 ^ 1]);
	scanf("%d", &q);
	for (int i = 1; i <= q; i++) {
		int l, r; scanf("%d%d", &l, &r);
		int g = 0;
		for (int x = l + M - 1, y = r + M + 1; x ^ y ^ 1; x >>= 1, y >>= 1) {
			if (x & 1 ^ 1) g = gcd(g, treegcd[x ^ 1]);
			if (y & 1) g = gcd(g, treegcd[y ^ 1]);
		}
		if (d[lower_bound(d + 1, d + tot + 1, g) - d] != g) printf("%d\n", r - l + 1);
		else printf("%d\n", r - l + 1 - query(rt[l - 1], rt[r], 1, tot, g));
	}
	return 0;
}


#include <cstdio>
#include <algorithm>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

using namespace std;

const int MAXN = 400001;
const int MAXT = 600001;

struct Node{
	int l, r, d;
}t[MAXT];

int n, M, q, size, a[MAXN], d[MAXN], rt[MAXN], treegcd[MAXN << 2];

__inline int gcd(int a, int b) {
	while (b != 0) {
		int r = a % b;
		a = b; b = r;
	}
	return a;
}

void insert(int rt, int &newrt, int l, int r, int x) {
	t[newrt = ++size] = t[rt]; t[newrt].d++;
	if (l == r) return;
	if (x <= (l + r >> 1)) insert(t[rt].l, t[newrt].l, l, l + r >> 1, x);
	else insert(t[rt].r, t[newrt].r, (l + r >> 1) + 1, r, x);
}

int query(int lrt, int rrt, int l, int r, int x) {
	if (l == r) return t[rrt].d - t[lrt].d;
	if (x <= (l + r >> 1)) return query(t[lrt].l, t[rrt].l, l, l + r >> 1, x);
	else return query(t[lrt].r, t[rrt].r, (l + r >> 1) + 1, r, x);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		d[i] = a[i];
	}
	sort(d + 1, d + n + 1);
	int tot = unique(d + 1, d + n + 1) - d - 1;
	for (M = 1; M <= n + 1; M <<= 1);
	for (int i = 1; i <= M + n; i++) treegcd[i] = 0;
	for (int i = 1; i <= n; i++) {
		treegcd[M + i] = a[i];
		int now = lower_bound(d + 1, d + tot + 1, a[i]) - d;
		insert(rt[i - 1], rt[i], 1, tot, now);
	}
	for (int i = M; i >= 1; i--) treegcd[i] = gcd(treegcd[i << 1], treegcd[i << 1 ^ 1]);
	scanf("%d", &q);
	for (int i = 1; i <= q; i++) {
		int l, r; scanf("%d%d", &l, &r);
		int g = 0;
		for (int x = l + M - 1, y = r + M + 1; x ^ y ^ 1; x >>= 1, y >>= 1) {
			if (x & 1 ^ 1) g = gcd(g, treegcd[x ^ 1]);
			if (y & 1) g = gcd(g, treegcd[y ^ 1]);
		}
		if (d[lower_bound(d + 1, d + tot + 1, g) - d] != g) printf("%d\n", r - l + 1);
		else{
			g = lower_bound(d + 1, d + tot + 1, g) - d;
			printf("%d\n", r - l + 1 - query(rt[l - 1], rt[r], 1, tot, g));
		}
	}
	return 0;
}


#include <cstdio>
#include <algorithm>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

using namespace std;

const int MAXN = 200001;
const int MAXT = 600001;

struct Node{
	int l, r, d;
}t[MAXT];

int n, M, q, size, a[MAXN], d[MAXN], rt[MAXN], treegcd[MAXN << 2];

__inline int gcd(int a, int b) {
	while (b != 0) {
		int r = a % b;
		a = b; b = r;
	}
	return a;
}

void insert(int rt, int &newrt, int l, int r, int x) {
	t[newrt = ++size] = t[rt]; t[newrt].d++;
	if (l == r) return;
	if (x <= (l + r >> 1)) insert(t[rt].l, t[newrt].l, l, l + r >> 1, x);
	else insert(t[rt].r, t[newrt].r, (l + r >> 1) + 1, r, x);
}

int query(int lrt, int rrt, int l, int r, int x) {
	if (l == r) return t[rrt].d - t[lrt].d;
	if (x <= (l + r >> 1)) return query(t[lrt].l, t[rrt].l, l, l + r >> 1, x);
	else return query(t[lrt].r, t[rrt].r, (l + r >> 1) + 1, r, x);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		d[i] = a[i];
	}
	sort(d + 1, d + n + 1);
	int tot = unique(d + 1, d + n + 1) - d - 1;
	for (M = 1; M <= n + 1; M <<= 1);
	for (int i = 1; i <= n; i++) {
		int now = treegcd[M + i] = lower_bound(d + 1, d + tot + 1, a[i]) - d;
		insert(rt[i - 1], rt[i], 1, tot, now);
	}
	for (int i = M; i >= 1; i--) treegcd[i] = gcd(treegcd[i << 1], treegcd[i << 1 ^ 1]);
	scanf("%d", &q);
	for (int i = 1; i <= q; i++) {
		int l, r; scanf("%d%d", &l, &r);
		int g = 0;
		for (int x = l + M - 1, y = r + M + 1; x ^ y ^ 1; x >>= 1, y >>= 1) {
			if (x & 1 ^ 1) g = gcd(g, treegcd[x ^ 1]);
			if (y & 1) g = gcd(g, treegcd[y ^ 1]);
		}
		printf("%d\n", r - l + 1 - query(rt[l - 1], rt[r], 1, tot, g));
	}
	return 0;
}


#include <cstdio>
#include <algorithm>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

using namespace std;

const int MAXN = 600001;
const int MAXT = 1000001;

struct Node{
	int l, r, d;
}t[MAXT];

int n, M, q, size, a[MAXN], d[MAXN], rt[MAXN], treegcd[MAXN << 2];

__inline int gcd(int a, int b) {
	while (b != 0) {
		int r = a % b;
		a = b; b = r;
	}
	return a;
}

void insert(int rt, int &newrt, int l, int r, int x) {
	t[newrt = ++size] = t[rt]; t[newrt].d++;
	if (l == r) return;
	if (x <= (l + r >> 1)) insert(t[rt].l, t[newrt].l, l, l + r >> 1, x);
	else insert(t[rt].r, t[newrt].r, (l + r >> 1) + 1, r, x);
}

int query(int lrt, int rrt, int l, int r, int x) {
	if (l == r) return t[rrt].d - t[lrt].d;
	if (x <= (l + r >> 1)) return query(t[lrt].l, t[rrt].l, l, l + r >> 1, x);
	else return query(t[lrt].r, t[rrt].r, (l + r >> 1) + 1, r, x);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		d[i] = a[i];
	}
	sort(d + 1, d + n + 1);
	int tot = unique(d + 1, d + n + 1) - d - 1;
	for (M = 1; M <= n + 1; M <<= 1);
	for (int i = 1; i <= M + n; i++) treegcd[i] = 0;
	for (int i = 1; i <= n; i++) {
		treegcd[M + i] = a[i];
		int now = lower_bound(d + 1, d + tot + 1, a[i]) - d;
		insert(rt[i - 1], rt[i], 1, tot, now);
	}
	for (int i = M; i >= 1; i--) treegcd[i] = gcd(treegcd[i << 1], treegcd[i << 1 ^ 1]);
	scanf("%d", &q);
	for (int i = 1; i <= q; i++) {
		int l, r; scanf("%d%d", &l, &r);
		int g = 0;
		for (int x = l + M - 1, y = r + M + 1; x ^ y ^ 1; x >>= 1, y >>= 1) {
			if (x & 1 ^ 1) g = gcd(g, treegcd[x ^ 1]);
			if (y & 1) g = gcd(g, treegcd[y ^ 1]);
		}
		if (d[lower_bound(d + 1, d + tot + 1, g) - d] != g) printf("%d\n", r - l + 1);
		else{
			g = lower_bound(d + 1, d + tot + 1, g) - d;
			printf("%d\n", r - l + 1 - query(rt[l - 1], rt[r], 1, tot, g));
		}
	}
	return 0;
}


#include <cstdio>
#include <algorithm>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

using namespace std;

const int MAXN = 1000001;
const int MAXT = 1000001;

struct Node{
	int l, r, d;
}t[MAXT];

int n, M, q, size, a[MAXN], d[MAXN], rt[MAXN], treegcd[MAXN << 2];

__inline int gcd(int a, int b) {
	while (b != 0) {
		int r = a % b;
		a = b; b = r;
	}
	return a;
}

void insert(int rt, int &newrt, int l, int r, int x) {
	t[newrt = ++size] = t[rt]; t[newrt].d++;
	if (l == r) return;
	if (x <= (l + r >> 1)) insert(t[rt].l, t[newrt].l, l, l + r >> 1, x);
	else insert(t[rt].r, t[newrt].r, (l + r >> 1) + 1, r, x);
}

int query(int lrt, int rrt, int l, int r, int x) {
	if (l == r) return t[rrt].d - t[lrt].d;
	if (x <= (l + r >> 1)) return query(t[lrt].l, t[rrt].l, l, l + r >> 1, x);
	else return query(t[lrt].r, t[rrt].r, (l + r >> 1) + 1, r, x);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		d[i] = a[i];
	}
	sort(d + 1, d + n + 1);
	int tot = unique(d + 1, d + n + 1) - d - 1;
	for (M = 1; M <= n + 1; M <<= 1);
	for (int i = 1; i <= M + n; i++) treegcd[i] = 0;
	for (int i = 1; i <= n; i++) {
		treegcd[M + i] = a[i];
		int now = lower_bound(d + 1, d + tot + 1, a[i]) - d;
		insert(rt[i - 1], rt[i], 1, tot, now);
	}
	for (int i = M; i >= 1; i--) treegcd[i] = gcd(treegcd[i << 1], treegcd[i << 1 ^ 1]);
	scanf("%d", &q);
	for (int i = 1; i <= q; i++) {
		int l, r; scanf("%d%d", &l, &r);
		int g = 0;
		for (int x = l + M - 1, y = r + M + 1; x ^ y ^ 1; x >>= 1, y >>= 1) {
			if (x & 1 ^ 1) g = gcd(g, treegcd[x ^ 1]);
			if (y & 1) g = gcd(g, treegcd[y ^ 1]);
		}
		if (d[lower_bound(d + 1, d + tot + 1, g) - d] != g) printf("%d\n", r - l + 1);
		else{
			g = lower_bound(d + 1, d + tot + 1, g) - d;
			printf("%d\n", r - l + 1 - query(rt[l - 1], rt[r], 1, tot, g));
		}
	}
	return 0;
}


#include <cstdio>
#include <algorithm>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

using namespace std;

const int MAXN = 1000001;
const int MAXT = 1000001;

struct Node{
	int l, r, d;
}t[MAXT * 20];

int n, M, q, size, a[MAXN], d[MAXN], rt[MAXN], treegcd[MAXN << 2];

__inline int gcd(int a, int b) {
	while (b != 0) {
		int r = a % b;
		a = b; b = r;
	}
	return a;
}

void insert(int rt, int &newrt, int l, int r, int x) {
	t[newrt = ++size] = t[rt]; t[newrt].d++;
	if (l == r) return;
	if (x <= (l + r >> 1)) insert(t[rt].l, t[newrt].l, l, l + r >> 1, x);
	else insert(t[rt].r, t[newrt].r, (l + r >> 1) + 1, r, x);
}

int query(int lrt, int rrt, int l, int r, int x) {
	if (l == r) return t[rrt].d - t[lrt].d;
	if (x <= (l + r >> 1)) return query(t[lrt].l, t[rrt].l, l, l + r >> 1, x);
	else return query(t[lrt].r, t[rrt].r, (l + r >> 1) + 1, r, x);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		d[i] = a[i];
	}
	sort(d + 1, d + n + 1);
	int tot = unique(d + 1, d + n + 1) - d - 1;
	for (M = 1; M <= n + 1; M <<= 1);
	for (int i = 1; i <= M + n; i++) treegcd[i] = 0;
	for (int i = 1; i <= n; i++) {
		treegcd[M + i] = a[i];
		int now = lower_bound(d + 1, d + tot + 1, a[i]) - d;
		insert(rt[i - 1], rt[i], 1, tot, now);
	}
	for (int i = M; i >= 1; i--) treegcd[i] = gcd(treegcd[i << 1], treegcd[i << 1 ^ 1]);
	scanf("%d", &q);
	for (int i = 1; i <= q; i++) {
		int l, r; scanf("%d%d", &l, &r);
		int g = 0;
		for (int x = l + M - 1, y = r + M + 1; x ^ y ^ 1; x >>= 1, y >>= 1) {
			if (x & 1 ^ 1) g = gcd(g, treegcd[x ^ 1]);
			if (y & 1) g = gcd(g, treegcd[y ^ 1]);
		}
		if (d[lower_bound(d + 1, d + tot + 1, g) - d] != g) printf("%d\n", r - l + 1);
		else{
			g = lower_bound(d + 1, d + tot + 1, g) - d;
			printf("%d\n", r - l + 1 - query(rt[l - 1], rt[r], 1, tot, g));
		}
	}
	return 0;
}


#include <cstdio>
#include <algorithm>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

using namespace std;

const int MAXN = 100001;
const int MAXT = 600001;

struct Node{
	int l, r, d;
}t[MAXT];

int n, M, q, size, a[MAXN], d[MAXN], rt[MAXN], treegcd[MAXN << 2];

__inline int gcd(int a, int b) {
	while (b != 0) {
		int r = a % b;
		a = b; b = r;
	}
	return a;
}

void insert(int rt, int &newrt, int l, int r, int x) {
	t[newrt = ++size] = t[rt]; t[newrt].d++;
	if (l == r) return;
	if (x <= (l + r >> 1)) insert(t[rt].l, t[newrt].l, l, l + r >> 1, x);
	else insert(t[rt].r, t[newrt].r, (l + r >> 1) + 1, r, x);
}

int query(int lrt, int rrt, int l, int r, int x) {
	if (l == r) return t[rrt].d - t[lrt].d;
	if (x <= (l + r >> 1)) return query(t[lrt].l, t[rrt].l, l, l + r >> 1, x);
	else return query(t[lrt].r, t[rrt].r, (l + r >> 1) + 1, r, x);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
		d[i] = a[i];
	}
	sort(d + 1, d + n + 1);
	int tot = unique(d + 1, d + n + 1) - d - 1;
	for (M = 1; M <= n + 1; M <<= 1);
	for (int i = 1; i <= n; i++) {
		treegcd[M + i] = a[i];
		int now = lower_bound(d + 1, d + tot + 1, a[i]) - d;
		insert(rt[i - 1], rt[i], 1, tot, now);
	}
	for (int i = M; i >= 1; i--) treegcd[i] = gcd(treegcd[i << 1], treegcd[i << 1 ^ 1]);
	scanf("%d", &q);
	for (int i = 1; i <= q; i++) {
		int l, r; scanf("%d%d", &l, &r);
		int g = 0;
		for (int x = l + M - 1, y = r + M + 1; x ^ y ^ 1; x >>= 1, y >>= 1) {
			if (x & 1 ^ 1) g = gcd(g, treegcd[x ^ 1]);
			if (y & 1) g = gcd(g, treegcd[y ^ 1]);
		}
		if (d[lower_bound(d + 1, d + tot + 1, g) - d] != g) printf("%d\n", r - l + 1);
		else printf("%d\n", r - l + 1 - query(rt[l - 1], rt[r], 1, tot, g));
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef string str;
#define forn(i, n) for (int i = 0; i < n; i++)
#define form(i, n, m) for (int i = n; i <= m; i++)
//
#define read(x) scanf("%d", &x)
#define write(x) printf("%d", &x)
#define read2(x, y) scanf("%d %d", &x, &y)
//
#define sqr(x) x*x
#define clr(a, x) memset(a, x, sizeof(a));
#define mp make_pair
#define pb push_back
#define pob pop_back
#define XX first
#define YY second
#define in insert
#define db long double
#define re return
#define y1 dsfgsdfgsdfgsdfgsdfgsdfg
#define sz size
#define rs resize
#define vec vector
#define all(a) a.begin(), a.end()
#define TASK "sum"   //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
const str LN = "\n";
const double eps = 1e-7;
const double pi = acos(-1.0);
const int INF = (int)2e9 + 7;
const ll LINF = (ll)9e18 + 7;
bool in(int k, int x1, int x2) {re (k >= x1 && k <= x2);}

const int MAXN = 60007;
const bool is_testing = 0;
const ll MOD = 1e9 + 7;

int n, m;
int a[100007];
int gcd_t[8*100007];
pair<int, int> min_t[8*100007];

inline void build(int v, int vl, int vr)
{
    if (vl == vr)
    {
        gcd_t[v] = a[vl];
    }
    else
    {
        int vm = (vl + vr) / 2;
        build(v * 2 + 1, vl, vm);
        build(v * 2 + 2, vm + 1, vr);
        gcd_t[v] = __gcd(gcd_t[v * 2 + 1], gcd_t[v * 2 + 2]);
    }
}

inline int get(int v, int vl, int vr, int l, int r)
{
    if (vr < l || vl > r)
        re INF;
    if (vl >= l && vr <= r)
    {
        re gcd_t[v];
    }
    else
    {
        int vm = (vl + vr) / 2;
        int q1 = get(v * 2 + 1, vl, vm, l, r);
        int q2 = get(v * 2 + 2, vm + 1, vr, l, r);
        if (q1 == INF)
            re q2;
        if (q2 == INF)
            re q1;
        re __gcd(q1, q2);
    }
}

inline void build_min(int v, int vl, int vr)
{
    if (vl == vr)
    {
        min_t[v].XX = a[vl];
        min_t[v].YY = 1;
    }
    else
    {
        int vm = (vl + vr) / 2;
        build_min(v * 2 + 1, vl, vm);
        build_min(v * 2 + 2, vm + 1, vr);
        if (min_t[v * 2 + 1].XX == min_t[v * 2 + 2].XX)
        {
            min_t[v].XX = min_t[v * 2 + 1].XX;
            min_t[v].YY = min_t[v * 2 + 1].YY + min_t[v * 2 + 2].YY;
        }
        else
        {
            min_t[v] = min(min_t[v * 2 + 1], min_t[v * 2 + 2]);
        }
    }
}

inline pair<int, int> get_min(int v, int vl, int vr, int l, int r)
{
    if (vr < l || vl > r)
        return mp(INF, INF);
    if (vl >= l && vr <= r)
    {
        re min_t[v];
    }
    else
    {
        int vm = (vl + vr) / 2;
        pair<int, int> q1 = get_min(v * 2 + 1, vl, vm, l, r);
        pair<int, int> q2 = get_min(v * 2 + 2, vm + 1, vr, l, r);
        if (q1 == mp(INF, INF))
            re q2;
        if (q2 == mp(INF, INF))
            re q1;
        if (q1.XX == q2.XX)
        {
            re mp(q1.XX, q1.YY + q2.YY);
        }
        else
        {
            re min(q1, q2);
        }
    }
}

int main()
{
	ios_base::sync_with_stdio(false);
    //freopen("lock.in", "r", stdin); freopen("lock.out", "w", stdout);
    if (is_testing)
    {
    }
    cin >> n;
    forn(i, n)
        cin >> a[i];
    build(0, 0, n - 1);
    build_min(0, 0, n - 1);
    cin >> m;
    forn(i, m)
    {
        int l, r;
        cin >> l >> r;
        l--; r--;
        int GCD = get(0, 0, n - 1, l, r);
        pair<int, int> q = get_min(0, 0, n - 1, l, r);
        //cout << GCD << ' ' << q.XX << ' ' << q.YY << LN;
        if (GCD == q.XX)
            cout << r - l - q.YY + 1;
        else
            cout << r - l + 1;
        cout << LN;
    }

}


/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . ___
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         佛祖保佑       永无BUG
*/
//use readint!
#pragma GCC optimize(1)
#pragma G++ optimize(1)
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#pragma GCC optimize(3)
#pragma G++ optimize(3)
#pragma GCC optimize(4)
#pragma G++ optimize(4)
#pragma GCC optimize(5)
#pragma G++ optimize(5)
#pragma GCC optimize(6)
#pragma G++ optimize(6)
#pragma GCC optimize(7)
#pragma G++ optimize(7)
#pragma GCC optimize(8)
#pragma G++ optimize(8)
#pragma GCC optimize(9)
#pragma G++ optimize(9)
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#include<map>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<stdio.h>
#include<fstream>
#include<assert.h>
#include<time.h>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<string.h>
#define mp make_pair
#define ll long long
#define all(v) v.begin(),v.end()
#define memset(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF=1e9;
inline int pt(int a[],int l,int r){
	int p,i,j;
	p=a[l];
	i=l;
	j=r+1;
	for(;;){
		while(a[++i]<p) if(i>=r) break;
		while(a[--j]>p) if(j<=l) break;
		if(i>=j) break;
		else swap(a[i],a[j]);
	}
	if(j==l) return j;
	swap(a[l],a[j]);
	return j;
}
inline void q_sort(int a[],int l,int r){
	int q;
	if(r>l){
		q=pt(a,l,r);
		q_sort(a,l,q-1);
		q_sort(a,q+1,r);
	}
}
inline void rd(long long &val){
    long long x=0;
    int f=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-'){
		f=-1;
		ch=getchar();
	}
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    val=x*f;
}
inline void quickSort(int s[],int l,int r)  {
    if(l<r){
        int i=l,j=r,x=s[l];
        while(i<j){
            while(i<j&&s[j]>=x) j--;
            if(i<j) s[i++]=s[j];
            while(i<j&&s[i]<x) i++;
            if(i<j) s[j--] = s[i];
        }
        s[i]=x;
        quickSort(s, l, i - 1);
        quickSort(s, i + 1, r);
    }
}
int n,T;
int tr[400005];
int gcd[400005];
int zh[400005];
vector<pair<int,int> > v;
inline void btr(int x,int l,int r){
	if(l==r){
		gcd[x]=zh[l];
		return;
	}
	btr(x*2,l,(l+r)/2);
	btr(x*2+1,(l+r)/2+1,r);
	gcd[x]=__gcd(gcd[x*2],gcd[x*2+1]);
}
inline int fdgcd(int x,int l,int r,int a,int b){
	if(l>b||r<a) return INF;
	if(l>=a&&r<=b) return gcd[x];
	if(l==r) return gcd[x];
	int p,q;
	p=fdgcd(x*2,l,(l+r)/2,a,b);
	q=fdgcd(x*2+1,(l+r)/2+1,r,a,b);
	if(p==INF&&q==INF) return INF;
	if(p==INF) return q;
	if(q==INF) return p;
	return __gcd(p,q);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int i,j,l,r,t,beg,end;
	cin>>n;
	for(i=1;i<=n;i++) cin>>zh[i];
	for(i=1;i<=n;i++) v.push_back(mp(zh[i],i));
	btr(1,1,n);
	sort(v.begin(),v.end());
	cin>>T;
	while(T--){
		cin>>l>>r;
		t=fdgcd(1,1,n,l,r);
		beg=lower_bound(v.begin(),v.end(),mp(t,l))-v.begin();
		end=upper_bound(v.begin(),v.end(),mp(t,r))-v.begin();
		cout<<r-l+1-(end-beg)<<endl;
	}
	return 0;
}
474


/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . ___
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         ·ð×æ±£ÓÓ       ÓÀÎÞBUG
*/
//use readint!
#pragma GCC optimize(1)
#pragma G++ optimize(1)
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#pragma GCC optimize(3)
#pragma G++ optimize(3)
#pragma GCC optimize(4)
#pragma G++ optimize(4)
#pragma GCC optimize(5)
#pragma G++ optimize(5)
#pragma GCC optimize(6)
#pragma G++ optimize(6)
#pragma GCC optimize(7)
#pragma G++ optimize(7)
#pragma GCC optimize(8)
#pragma G++ optimize(8)
#pragma GCC optimize(9)
#pragma G++ optimize(9)
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#include<map>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<stdio.h>
#include<fstream>
#include<assert.h>
#include<time.h>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<string.h>
#define mp make_pair
#define ll long long
#define all(v) v.begin(),v.end()
#define memset(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF=1e9;
inline int pt(int a[],int l,int r){
	int p,i,j;
	p=a[l];
	i=l;
	j=r+1;
	for(;;){
		while(a[++i]<p) if(i>=r) break;
		while(a[--j]>p) if(j<=l) break;
		if(i>=j) break;
		else swap(a[i],a[j]);
	}
	if(j==l) return j;
	swap(a[l],a[j]);
	return j;
}
inline void q_sort(int a[],int l,int r){
	int q;
	if(r>l){
		q=pt(a,l,r);
		q_sort(a,l,q-1);
		q_sort(a,q+1,r);
	}
}
inline void rd(long long &val){
    long long x=0;
    int f=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-'){
		f=-1;
		ch=getchar();
	}
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    val=x*f;
}
inline void quickSort(int s[],int l,int r)  {
    if(l<r){
        int i=l,j=r,x=s[l];
        while(i<j){
            while(i<j&&s[j]>=x) j--;
            if(i<j) s[i++]=s[j];
            while(i<j&&s[i]<x) i++;
            if(i<j) s[j--] = s[i];
        }
        s[i]=x;
        quickSort(s, l, i - 1);
        quickSort(s, i + 1, r);
    }
}
int n,T;
int tr[400005];
int gcd[400005];
int zh[400005];
vector<pair<int,int> > v;
inline void btr(int x,int l,int r){
	if(l==r){
		gcd[x]=zh[l];
		return;
	}
	btr(x*2,l,(l+r)/2);
	btr(x*2+1,(l+r)/2+1,r);
	gcd[x]=__gcd(gcd[x*2],gcd[x*2+1]);
}
inline int fdgcd(int x,int l,int r,int a,int b){
	if(l>b||r<a) return INF;
	if(l>=a&&r<=b) return gcd[x];
	if(l==r) return gcd[x];
	int p,q;
	p=fdgcd(x*2,l,(l+r)/2,a,b);
	q=fdgcd(x*2+1,(l+r)/2+1,r,a,b);
	if(p==INF){
		if(q==INF) return INF;
		return q;
	}
	if(q==INF){
		if(p==INF) return INF;
		return p;
	}
	return __gcd(p,q);
}
int main(){
	ios_base::sync_with_stdio(false);
	int i,j,l,r,t,beg,end;
	cin>>n;
	for(i=1;i<=n;i++) cin>>zh[i];
	for(i=1;i<=n;i++) v.push_back(mp(zh[i],i));
	btr(1,1,n);
	sort(v.begin(),v.end());
	cin>>T;
	while(T--){
		cin>>l>>r;
		t=fdgcd(1,1,n,l,r);
//		cout<<t<<endl;
		beg=lower_bound(v.begin(),v.end(),mp(t,l))-v.begin();
		end=upper_bound(v.begin(),v.end(),mp(t,r))-v.begin();
		cout<<r-l+1-(end-beg)<<endl;
	}
	return 0;
}


/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . ___
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         佛祖保佑       永无BUG
*/
//use readint!
#pragma GCC optimize(1)
#pragma G++ optimize(1)
#pragma GCC optimize(2)
#pragma G++ optimize(2)
#pragma GCC optimize(3)
#pragma G++ optimize(3)
#pragma GCC optimize(4)
#pragma G++ optimize(4)
#pragma GCC optimize(5)
#pragma G++ optimize(5)
#pragma GCC optimize(6)
#pragma G++ optimize(6)
#pragma GCC optimize(7)
#pragma G++ optimize(7)
#pragma GCC optimize(8)
#pragma G++ optimize(8)
#pragma GCC optimize(9)
#pragma G++ optimize(9)
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#include<map>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<cmath>
#include<stdio.h>
#include<fstream>
#include<assert.h>
#include<time.h>
#include<queue>
#include<deque>
#include<stack>
#include<list>
#include<string.h>
#define mp make_pair
#define ll long long
#define all(v) v.begin(),v.end()
#define memset(a,b) memset(a,b,sizeof(a))
using namespace std;
const int INF=1e9;
inline int pt(int a[],int l,int r){
	int p,i,j;
	p=a[l];
	i=l;
	j=r+1;
	for(;;){
		while(a[++i]<p) if(i>=r) break;
		while(a[--j]>p) if(j<=l) break;
		if(i>=j) break;
		else swap(a[i],a[j]);
	}
	if(j==l) return j;
	swap(a[l],a[j]);
	return j;
}
inline void q_sort(int a[],int l,int r){
	int q;
	if(r>l){
		q=pt(a,l,r);
		q_sort(a,l,q-1);
		q_sort(a,q+1,r);
	}
}
inline void rd(long long &val){
    long long x=0;
    int f=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-'){
		f=-1;
		ch=getchar();
	}
    while(ch>='0'&&ch<='9'){
        x=x*10+ch-'0';
        ch=getchar();
    }
    val=x*f;
}
inline void quickSort(int s[],int l,int r)  {
    if(l<r){
        int i=l,j=r,x=s[l];
        while(i<j){
            while(i<j&&s[j]>=x) j--;
            if(i<j) s[i++]=s[j];
            while(i<j&&s[i]<x) i++;
            if(i<j) s[j--] = s[i];
        }
        s[i]=x;
        quickSort(s, l, i - 1);
        quickSort(s, i + 1, r);
    }
}
int n,T;
int gcd[200011];
int zh[200011];
vector<pair<int,int> > v;
inline void btr(int x,int l,int r){
	if(l==r){
		gcd[x]=zh[l];
		return;
	}
	btr(x*2,l,(l+r)/2);
	btr(x*2+1,(l+r)/2+1,r);
	gcd[x]=__gcd(gcd[x*2],gcd[x*2+1]);
}
inline int fdgcd(int x,int l,int r,int a,int b){
	if(l>b||r<a) return INF;
	if(l>=a&&r<=b) return gcd[x];
	if(l==r) return gcd[x];
	int p,q;
	p=fdgcd(x*2,l,(l+r)/2,a,b);
	q=fdgcd(x*2+1,(l+r)/2+1,r,a,b);
	if(p==INF&&q==INF) return INF;
	if(p==INF) return q;
	if(q==INF) return p;
	return __gcd(p,q);
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int i,j,l,r,t,beg,end;
	cin>>n;
	for(i=1;i<=n;i++) cin>>zh[i];
	for(i=1;i<=n;i++) v.push_back(mp(zh[i],i));
	btr(1,1,n);
	sort(v.begin(),v.end());
	cin>>T;
	while(T--){
		cin>>l>>r;
		t=fdgcd(1,1,n,l,r);
		beg=lower_bound(v.begin(),v.end(),mp(t,l))-v.begin();
		end=upper_bound(v.begin(),v.end(),mp(t,r))-v.begin();
		cout<<r-l+1-(end-beg)<<endl;
	}
	return 0;
}