#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
const int maxm = 1e7 + 100;
const int mod = 1e9 + 7;
const int inf = 1e18;
int n, a, x, m, l, r, p[maxm], cnt[maxm];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  for (int i = 2; i * i < maxm; i++) {
    if (p[i]) continue;
    p[i] = i;
    for (int j = i * i; j < maxm; j += i) {
      p[j] = i;
    }
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    while (a != 1) {
      x = p[a];
      if (x == 0) x = a;
      while (a % x == 0) {
        a /= x;
      }
      cnt[x]++;
    }
  }
  for (int i = 1; i < maxm; i++) {
    cnt[i] += cnt[i - 1];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> l >> r;
    if (l >= maxm) l = maxm - 1;
    if (r >= maxm) r = maxm - 1;
    cout << cnt[r] - cnt[l - 1] << endl;
  }
  return 0;
}
