#include <bits/stdc++.h>
using namespace std;
const int M = 2e7 + 5;
bool prim[M];
int pref[M], fmp[M];
void seive() {
  memset(prim, 1, sizeof(prim));
  prim[0] = prim[1] = 0;
  for (int i = 2; i < M; i++) {
    if (prim[i] == 1) {
      for (int j = i * i; j < M && j > 0; j += i) {
        prim[j] = 0;
      }
    }
  }
}
void factor(long long x) {
  int org = x;
  for (long long i = 2; i * i <= x; i++) {
    if (prim[x]) {
      fmp[x] += pref[org];
      return;
    }
    if (x % i == 0) {
      fmp[i] += pref[org];
      while (x % i == 0) x /= i;
    }
  }
  if (x > 1) fmp[x] += pref[org];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  seive();
  memset(pref, 0, sizeof(pref));
  int n, x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    pref[x]++;
  }
  for (int i = 0; i < M; i++)
    if (pref[i] > 0) factor(i);
  for (int i = 1; i < M - 3; i++) fmp[i] += fmp[i - 1];
  long long m, l, r;
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    r = min((long long)M - 5, r);
    l = min((long long)M - 5, l);
    int ans = fmp[r] - fmp[l - 1];
    cout << (ans) << "\n";
  }
  return 0;
}
