#include <bits/stdc++.h>
using namespace std;
const long long maxn = 500005;
const long long maxVal = 1e9;
struct Val {
  long long minVal, minCnt, gcd;
  Val() {
    minVal = gcd = maxVal;
    gcd = 1;
  }
} val[maxn << 2];
long long Gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  while (b) {
    int t = b;
    b = a % b;
    a = t;
  }
  return a;
}
void PushUp(long long rt) {
  if (val[rt << 1].minVal == val[rt << 1 | 1].minVal) {
    val[rt].minCnt = val[rt << 1].minCnt + val[rt << 1 | 1].minCnt;
  } else if (val[rt << 1].minVal < val[rt << 1 | 1].minVal) {
    val[rt].minCnt = val[rt << 1].minCnt;
  } else
    val[rt].minCnt = val[rt << 1 | 1].minCnt;
  val[rt].minVal = min(val[rt << 1].minVal, val[rt << 1 | 1].minVal);
  val[rt].gcd = Gcd(val[rt << 1].gcd, val[rt << 1 | 1].gcd);
}
void build(long long l, long long r, long long rt) {
  if (l == r) {
    cin >> val[rt].minVal;
    val[rt].minCnt = 1;
    val[rt].gcd = val[rt].minVal;
    return;
  }
  long long m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  PushUp(rt);
}
Val query(long long L, long long R, long long l, long long r, long long rt) {
  if (L <= l && r <= R) {
    return val[rt];
  }
  int m = (l + r) >> 1;
  Val res;
  bool flagL = false;
  if (L <= m) {
    flagL = true;
    res = query(L, R, l, m, rt << 1);
  }
  if (R > m) {
    if (flagL) {
      Val tmp = query(L, R, m + 1, r, rt << 1 | 1);
      if (res.minVal == tmp.minVal)
        res.minCnt += tmp.minCnt;
      else if (res.minVal > tmp.minVal) {
        res.minCnt = tmp.minCnt;
        res.minVal = tmp.minVal;
      }
      res.gcd = Gcd(res.gcd, tmp.gcd);
    } else {
      res = query(L, R, m + 1, r, rt << 1 | 1);
    }
  }
  return res;
}
int main() {
  ios::sync_with_stdio(false);
  int t;
  long long N, M;
  cin >> N;
  build(1, N, 1);
  cin >> M;
  for (int i = 0; i < M; i++) {
    long long l, r;
    cin >> l >> r;
    Val res = query(l, r, 1, N, 1);
    if (res.minVal == res.gcd) {
      cout << r - l + 1 - res.minCnt << '\n';
    } else
      cout << r - l + 1 << '\n';
  }
  return 0;
}
