#include <bits/stdc++.h>
using namespace std;
int main() {
  std::ios_base::sync_with_stdio(false);
  int n, i, p, x;
  cin >> n;
  int N = 10000000;
  vector<int> prime(N + 10, 0), ans(N + 10, 0), make_pair(N + 10, 0);
  for (i = 0; i < n; i++) {
    cin >> x;
    make_pair[x]++;
  }
  for (p = 2; p <= N; p++) {
    if (prime[p] == 0) {
      for (i = p; i <= N; i += p) {
        ans[p] += make_pair[i];
        prime[i] = 1;
      }
    }
  }
  vector<int> pre(N + 1);
  pre[0] = 0;
  for (i = 1; i <= N; i++) {
    pre[i] = pre[i - 1] + ans[i];
  }
  int m;
  cin >> m;
  while (m--) {
    int l, r;
    cin >> l >> r;
    if (l > N) l = N;
    if (r > N) r = N;
    cout << pre[r] - pre[l - 1] << '\n';
  }
  return 0;
}
