#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll maxum = 10000001;
  vector<ll> spf(maxum, 0);
  for (ll i = 1; i < maxum; i++) {
    spf[i] = i;
    if (i % 2 == 0) spf[i] = 2;
  }
  for (ll i = 3; i * i <= maxum; i++) {
    if (spf[i] == i) {
      for (ll j = i * i; j < maxum; j += i) {
        if (spf[j] == j && j % i == 0) spf[j] = i;
      }
    }
  }
  ll n;
  cin >> n;
  ll a[n];
  vector<ll> pr(maxum, 0);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    ll k = spf[a[i]];
    while (a[i] > 1) {
      while (a[i] % k == 0) {
        a[i] /= k;
      }
      pr[k]++;
      k = spf[a[i]];
    }
  }
  for (ll i = 3; i < maxum; i++) pr[i] += pr[i - 1];
  int m;
  cin >> m;
  for (ll i = 0; i < m; i++) {
    ll l, r;
    cin >> l >> r;
    l = min(l, maxum - 1);
    r = min(r, maxum - 1);
    if (l <= r) cout << pr[r] - pr[l - 1] << endl;
  }
}
