#include <bits/stdc++.h>
using namespace std;
int mark[10000002];
bool prime[10000002] = {0};
int sum[10000002] = {0};
int main() {
  std::ios::sync_with_stdio(false);
  int n, x, m, l, r;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    mark[x]++;
  }
  for (int i = 2; i <= 10000000; i++) {
    if (prime[i] == false) {
      int ct = 0;
      for (int j = i; j <= 10000000; j += i) prime[j] = true, ct += mark[j];
      sum[i] = ct;
    }
  }
  for (int i = 1; i <= 10000000; i++) sum[i] += sum[i - 1];
  cin >> m;
  while (m--) {
    cin >> l >> r;
    l = min(10000000, l);
    r = min(10000000, r);
    cout << sum[r] - sum[l - 1] << endl;
  }
}
