#include <bits/stdc++.h>
using namespace std;
int lp[10000000 + 100], c[10000000 + 100];
unordered_map<int, int> p;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  memset(c, 0, sizeof(c));
  int n, i, j;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
    c[a[i]]++;
  }
  vector<int> pr;
  for (i = 2; i <= 10000000; ++i) {
    if (lp[i] == 0) {
      lp[i] = i;
      p[i] += c[i];
      pr.push_back(i);
    }
    for (j = 0; j < pr.size() && pr[j] <= lp[i] && i * pr[j] <= 10000000; ++j) {
      lp[i * pr[j]] = pr[j];
      if (lp[i] != pr[j]) {
        p[lp[i]] += c[i * pr[j]];
      }
      p[pr[j]] += c[i * pr[j]];
    }
  }
  for (i = 1; i <= 10000000; ++i) {
    p[i] += p[i - 1];
  }
  long long int m, d = 10000000;
  cin >> m;
  while (m--) {
    long long int l, r;
    cin >> l >> r;
    r = min(r, d);
    cout << p[r] - p[l - 1] << "\n";
  }
}
