#include <bits/stdc++.h>
using namespace std;
long long arr[1000011], loga[1000011], sparse[1000011][25 + 1];
pair<long long, long long> lol[1000011];
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, q, l, r, a, x, y, k;
  pair<long long, long long> b;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    lol[i] = {arr[i], i};
  }
  loga[1] = 0;
  for (long long i = 2; i < 1000011; i++) loga[i] = loga[i / 2] + 1;
  for (long long i = 0; i < n; i++) sparse[i][0] = arr[i];
  for (long long j = 1; j <= 25; j++) {
    for (long long i = 0; i + (1 << j) <= n; i++)
      sparse[i][j] = gcd(sparse[i][j - 1], sparse[i + (1 << (j - 1))][j - 1]);
  }
  cin >> q;
  sort(lol, lol + n);
  while (q--) {
    cin >> l >> r;
    k = loga[(r - 1) - (l - 1) + 1];
    a = gcd(sparse[l - 1][k], sparse[(r - 1) - (1 << k) + 1][k]);
    b = {a, l - 1};
    x = (lower_bound(lol, lol + n, b) - lol);
    b = {a, r};
    y = (lower_bound(lol, lol + n, b) - lol);
    cout << (r - l + 1) - (y - x) << '\n';
  }
  return 0;
}
