#include <bits/stdc++.h>
using namespace std;
class compare {
 public:
  bool operator()(pair<long long, pair<long long, long long>> a,
                  pair<long long, pair<long long, long long>> b) {
    if (a.first < b.first)
      return true;
    else if (a.first == b.first)
      return a.second.first > b.second.first;
    return false;
  }
};
bool comp(long long a, long long b) { return a > b; }
long long power(long long a, long long b) {
  long long res = 1;
  a = a % 1000000007;
  while (b) {
    if (b & 1) {
      res = (res * a) % 1000000007;
    }
    b /= 2;
    a = (a * a) % 1000000007;
  }
  return res;
}
const long long N = 10000011;
long long fac[N];
long long cnt[N];
long long pre[N];
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    cnt[x]++;
  }
  for (long long i = 2; i < N; i++) {
    if (fac[i] == 0)
      for (long long j = i; j < N; j += i) {
        pre[i] += cnt[j];
        fac[j]++;
      }
    pre[i] += pre[i - 1];
  }
  long long m;
  cin >> m;
  for (long long i = 0; i < m; i++) {
    long long l, r;
    cin >> l >> r;
    r = min(r, (long long)1e7);
    l = min(l, r);
    cout << pre[r] - pre[l - 1] << "\n";
  }
  return 0;
}
