#include <bits/stdc++.h>
using namespace std;
vector<bool> pr(10000000 + 1, true);
vector<long long> first(10000000 + 1, 0);
vector<long long> cnt(10000000 + 1, 0);
vector<long long> pre(10000000 + 1, 0);
void mod_sieve() {
  pr[0] = false;
  pr[1] = false;
  for (long long i = 2; i <= 10000000; i++) {
    if (pr[i]) {
      for (long long j = i; j <= 10000000; j += i) {
        pr[j] = false;
        first[i] += cnt[j];
      }
    }
    pre[i] = pre[i - 1] + first[i];
  }
}
int main(void) {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n;
  vector<long long> x(n, 0);
  for (long long i = 0; i <= n - 1; i++) {
    cin >> x[i];
    cnt[x[i]]++;
  }
  mod_sieve();
  cin >> m;
  for (long long i = 0; i <= m - 1; i++) {
    long long l, r;
    cin >> l >> r;
    if (r > 10000000) r = 10000000;
    if (l > 10000000) l = 10000000;
    cout << pre[r] - pre[l - 1] << "\n";
  }
  return 0;
}
