#include <bits/stdc++.h>
#pragma gcc optimize("ofast")
using namespace std;
long long modexp(long long a, long long b, long long m) {
  long long r = 1;
  a = a % m;
  while (b > 0) {
    if (b & 1) r = (r * a) % m;
    b = b / 2;
    a = (a * a) % m;
  }
  return r % m;
}
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
vector<long long> bit;
vector<long long> segtree;
vector<long long> segleaf;
vector<long long> segcd;
void bit_update(long long x, long long n, long long val) {
  while (x < n) {
    bit[x] += val;
    x += (x & (~x + 1));
  }
}
long long bit_sum(long long x) {
  long long sum = 0;
  while (x > 0) {
    sum += bit[x];
    x -= (x & (~x + 1));
  }
  return sum;
}
void build(long long n, long long s, long long e) {
  if (s > e) return;
  if (s == e) {
    segtree[n] = 1;
    segcd[n] = segleaf[s];
    return;
  }
  long long mid = (s + e) / 2;
  build(2 * n, s, mid);
  build(2 * n + 1, mid + 1, e);
  long long gcd1 = segcd[2 * n];
  long long gcd2 = segcd[2 * n + 1];
  long long gcd3 = gcd(gcd1, gcd2);
  if (gcd3 == gcd1) segtree[n] += segtree[2 * n];
  if (gcd3 == gcd2) segtree[n] += segtree[2 * n + 1];
  segcd[n] = gcd3;
  return;
}
pair<long long, long long> gquery(long long n, long long s, long long e,
                                  long long l, long long r) {
  pair<long long, long long> ret;
  if (l > e || s > e || r < s) {
    ret.first = 0;
    ret.second = 0;
    return ret;
  }
  if (s >= l && e <= r) {
    ret.first = segcd[n];
    ret.second = segtree[n];
    return ret;
  }
  long long mid = (s + e) / 2;
  pair<long long, long long> gcd1 = gquery(2 * n, s, mid, l, r);
  pair<long long, long long> gcd2 = gquery(2 * n + 1, mid + 1, e, l, r);
  pair<long long, long long> gcd3;
  gcd3.first = gcd(gcd1.first, gcd2.first);
  gcd3.second = 0;
  if (gcd3.first == gcd1.first) gcd3.second += gcd1.second;
  if (gcd3.first == gcd2.first) gcd3.second += gcd2.second;
  return gcd3;
}
int main() {
  long long n;
  cin >> n;
  segleaf.resize(n + 1);
  for (long long i = 1; i < n + 1; i++) cin >> segleaf[i];
  long long t;
  cin >> t;
  segtree.resize(4 * n, 0);
  segcd.resize(4 * n, 0);
  build(1, 1, n);
  while (t--) {
    long long l, r;
    cin >> l >> r;
    long long x = gquery(1, 1, n, l, r).second;
    cout << r - l + 1 - x << endl;
  }
  return 0;
}
