#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  vector<int> primes;
  vector<char> isPrime(10000010, true);
  isPrime[0] = isPrime[1] = false;
  for (long long i = 2; i < 10000010; i++) {
    if (isPrime[i]) {
      for (long long j = i * i; j < 10000010; j += i) {
        isPrime[j] = false;
      }
      primes.push_back(i);
    }
  }
  int n;
  cin >> n;
  vector<int> S(10000011, 0);
  vector<int> D(10000011, 0);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    int rt = (int)sqrt(x);
    for (int j = 0; j < primes.size(); j++) {
      if (primes[j] > rt) break;
      bool div = false;
      while (x % primes[j] == 0) {
        div = true;
        x /= primes[j];
      }
      if (div) {
        S[j]++;
      }
    }
    if (x != 1) {
      int j = lower_bound(primes.begin(), primes.end(), x) - primes.begin();
      S[j]++;
    }
  }
  partial_sum(S.begin(), S.end(), D.begin());
  int m;
  cin >> m;
  while (m--) {
    int l, r;
    cin >> l >> r;
    int lp = lower_bound(primes.begin(), primes.end(), l) - primes.begin();
    int rp =
        prev(upper_bound(primes.begin(), primes.end(), r)) - primes.begin();
    cout << D[rp] - (lp ? D[lp - 1] : 0) << '\n';
  }
  return 0;
}
