#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  vector<int> x(n);
  for (int i = 0; i < n; ++i) scanf("%d", &x[i]);
  const int maxv = 1e7 + 100;
  vector<int> f(maxv);
  for (int i = 2; i < maxv; ++i)
    if (!f[i])
      for (int j = i; j < maxv; j += i)
        if (!f[j]) f[j] = i;
  vector<int> cnt(maxv);
  for (int i = 0; i < n; ++i) {
    vector<int> facts;
    int val = x[i];
    while (val > 1 && f[val]) {
      facts.push_back(f[val]);
      val /= f[val];
    }
    for (int j = 0; j < facts.size(); ++j)
      if (j == 0 || facts[j] != facts[j - 1]) cnt[facts[j]]++;
  }
  vector<long long> pref(maxv + 1);
  for (int i = 0; i < maxv; ++i) pref[i + 1] = pref[i] + cnt[i];
  int m;
  scanf("%d", &m);
  while (m--) {
    int l, r;
    scanf("%d %d", &l, &r);
    r = min(r, maxv - 1);
    l = min(l, r);
    printf("%I64d\n", pref[r + 1] - pref[l]);
  }
  return 0;
}
