#include <bits/stdc++.h>
using namespace std;
long long n, arr[100005], stsum[300005], q, l, r;
vector<pair<int, int> > stmin;
bool f, ch;
void buildmin(int a, int b, int pos) {
  if (a == b) {
    stmin[pos].first = arr[a];
    stmin[pos].second = 1;
    return;
  } else {
    int m = (a + b) / 2;
    buildmin(a, m, pos * 2 + 1);
    buildmin(m + 1, b, pos * 2 + 2);
    if (stmin[pos * 2 + 1].first == stmin[pos * 2 + 2].first) {
      stmin[pos].first = stmin[pos * 2 + 1].first;
      stmin[pos].second = stmin[pos * 2 + 1].second + stmin[pos * 2 + 2].second;
    } else {
      if (stmin[pos * 2 + 1].first < stmin[pos * 2 + 2].first) {
        stmin[pos].first = stmin[pos * 2 + 1].first;
        stmin[pos].second = stmin[pos * 2 + 1].second;
      } else {
        stmin[pos].first = stmin[pos * 2 + 2].first;
        stmin[pos].second = stmin[pos * 2 + 2].second;
      }
    }
  }
}
int gcd(int a, int b) {
  if (a < b) swap(a, b);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
void buildeuc(int a, int b, int pos) {
  if (a == b) {
    stsum[pos] = arr[a];
    return;
  }
  int m = (a + b) / 2;
  buildeuc(a, m, pos * 2 + 1);
  buildeuc(m + 1, b, pos * 2 + 2);
  stsum[pos] = gcd(stsum[pos * 2 + 1], stsum[pos * 2 + 2]);
}
pair<int, int> mini(int qa, int qb, int a, int b, int pos) {
  if (qa <= a && qb >= b) return stmin[pos];
  if (qa > b || qb < a) return make_pair(1000000001, 1000000001);
  int m = (a + b) / 2;
  pair<int, int> r1 = mini(qa, qb, a, m, pos * 2 + 1);
  pair<int, int> r2 = mini(qa, qb, m + 1, b, pos * 2 + 2);
  if (r1.first == r2.first)
    return make_pair(r1.first, r1.second + r2.second);
  else
    return min(r1, r2);
}
int euc(int qa, int qb, int a, int b, int pos) {
  if (qa <= a && qb >= b) return stsum[pos];
  if (qa > b || qb < a) return -1;
  int m = (a + b) / 2;
  int val1 = euc(qa, qb, a, m, pos * 2 + 1);
  int val2 = euc(qa, qb, m + 1, b, pos * 2 + 2);
  if (val1 == -1) val1 = val2;
  if (val2 == -1) val2 = val1;
  return gcd(val1, val2);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  stmin.resize(300005);
  for (int i = 0; i < n; i++) cin >> arr[i];
  buildmin(0, n - 1, 0);
  buildeuc(0, n - 1, 0);
  cin >> q;
  while (q--) {
    cin >> l >> r;
    pair<int, int> minimo = mini(l - 1, r - 1, 0, n - 1, 0);
    int div = euc(l - 1, r - 1, 0, n - 1, 0);
    if (div % minimo.first != 0)
      cout << r - l + 1 << '\n';
    else
      cout << r - l + 1 - minimo.second << '\n';
  }
}
