#include <bits/stdc++.h>
using namespace std;
const long long c = 1e7 + 5;
long long spf[c], cnt[c];
void seive() {
  for (int i = 1; i < c; i++) spf[i] = i;
  for (long long i = 2; i * i < c; i++)
    if (spf[i] == i)
      for (long long j = i * i; j < c; j += i)
        if (spf[j] == j) spf[j] = i;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  long long n, m, l, r, fact;
  seive();
  cin >> n;
  long long inp;
  for (int i = 0; i < n; i++) {
    cin >> inp;
    while (inp != 1) {
      fact = spf[inp];
      cnt[fact]++;
      while (inp != 1 && inp % fact == 0) inp /= fact;
    }
  }
  for (int i = 1; i < c; i++) cnt[i] += cnt[i - 1];
  cin >> m;
  while (m--) {
    cin >> l >> r;
    if (r >= c) r = c - 1;
    if (l >= c) l = c - 1;
    cout << cnt[r] - cnt[l - 1] << "\n";
  }
  return 0;
}
