#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int N = 1e7 + 1;
const int mod = 1e9 + 7;
void solve() {
  int n;
  cin >> n;
  vector<int> d(N);
  vector<int> c(N);
  vector<int> g(N);
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    c[x]++;
  }
  for (int i = 2; i < N; i++) {
    if (!g[i]) {
      for (int j = i; j < N; j += i) {
        d[i] += c[j];
        g[j] = 1;
      }
    }
  }
  for (int i = 1; i < N; i++) {
    d[i] += d[i - 1];
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    if (l >= N) {
      cout << "0\n";
      continue;
    }
    if (r >= N) r = N - 1;
    cout << d[r] - d[l - 1] << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
}
