#include <bits/stdc++.h>
using namespace std;
const int mxn = 10000001;
int modpow(int x, int n, int m) {
  x %= m;
  int res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % m;
    x = x * x % m;
    n >>= 1;
  }
  return res;
}
int carr[mxn] = {0};
bool primes[mxn] = {0};
int fn[mxn] = {0};
void solve() {
  int n, m;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    carr[v[i]]++;
  }
  cin >> m;
  primes[2] = 1;
  for (int i = 3; i < mxn; i += 2) {
    primes[i] = 1;
  }
  for (long long int i = 3; i < mxn; i += 2) {
    if (primes[i] && i * i <= mxn) {
      for (int j = i * i; j <= mxn; j += i) {
        primes[j] = 0;
      }
    }
  }
  vector<int> prime;
  for (int i = 2; i < mxn; i++) {
    if (primes[i]) {
      prime.push_back(i);
    }
  }
  for (int i = 0; i < (int)prime.size(); i++) {
    int k = prime[i];
    for (int j = prime[i]; j <= mxn; j += k) {
      fn[k] += carr[j];
    }
  }
  long long sum = fn[0];
  for (int i = 1; i < mxn; i++) {
    sum += fn[i];
    fn[i] = sum;
    sum = fn[i];
  }
  for (int i = 0; i < m; i++) {
    long long l, r;
    cin >> l >> r;
    l = min(l, (long long)(mxn - 1));
    r = min(r, (long long)(mxn - 1));
    cout << fn[r] - fn[l - 1] << endl;
  }
  return;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
