#include <bits/stdc++.h>
using namespace std;
map<int, vector<int>> f;
vector<vector<int>> st;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    f[s[i]].push_back(i + 1);
  }
  int maxk = 31 - __builtin_clz(n);
  st.resize(n, vector<int>(maxk + 1));
  for (int i = 0; i < n; i++) st[i][0] = s[i];
  for (int k = 1; k <= maxk; k++) {
    int len = 1 << (k - 1);
    for (int i = 0; i < n && i + 2 * len - 1 < n; i++) {
      st[i][k] = gcd(st[i][k - 1], st[i + len][k - 1]);
    }
  }
  int test;
  cin >> test;
  while (test--) {
    int l, r;
    cin >> l >> r;
    int dist = r - l + 1;
    int k = 31 - __builtin_clz(dist);
    int g = gcd(st[l - 1][k], st[r - (1 << k)][k]);
    int saved;
    if (f.count(g) == 0)
      saved = 0;
    else {
      int start = lower_bound(f[g].begin(), f[g].end(), l) - f[g].begin();
      int ennd = upper_bound(f[g].begin(), f[g].end(), r) - f[g].begin();
      saved = ennd - start;
    }
    cout << r - l + 1 - saved << "\n";
  }
  return 0;
}
