#include <bits/stdc++.h>
using namespace std;
bool compare(long long &x, long long &y) { return x >= y; }
long long mode = pow(10, 9) + 7;
long long maxxx = 10000001;
vector<long long> spf(10000001, 0);
vector<long long> pre(10000001, 0);
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < maxxx; i += 2) {
    spf[i] = 2;
  }
  for (int i = 3; i < maxxx; i++) {
    if (spf[i] == 0) {
      spf[i] = i;
      for (int j = 2 * i; j < maxxx; j += i) {
        if (spf[j] == 0) spf[j] = i;
      }
    }
  }
}
void getfactor(long long n) {
  long long x, lastPrime = 0;
  x = n;
  while (x > 1) {
    if (spf[x] != lastPrime) pre[spf[x]]++;
    lastPrime = spf[x];
    x /= spf[x];
  }
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  sieve();
  long long n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<long long> freq(maxxx, 0);
  for (int i = 0; i < n; i++) {
    getfactor(a[i]);
  }
  pre[0] = 0;
  pre[1] = 0;
  for (int i = 2; i < maxxx; i++) {
    pre[i] += pre[i - 1];
  }
  long long m;
  cin >> m;
  while (m--) {
    long long a, b;
    cin >> a >> b;
    a = min(a, maxxx - 1);
    b = min(b, maxxx - 1);
    cout << pre[b] - pre[a - 1] << "\n";
  }
  return 0;
}
