#include <bits/stdc++.h>
using namespace std;
int primes[(int)10000000 + 42] = {0};
int fp[(int)10000000 + 42] = {0};
int occurs[(int)10000000 + 42] = {0};
int cumul[(int)10000000 + 42] = {0};
vector<int> vv;
void sieve() {
  for (int i = 2; i <= 10000000; i++) {
    if (primes[i] == 0) {
      fp[i] += occurs[i];
      for (int j = 2 * i; j <= 10000000; j += i) {
        primes[j] = 1;
        fp[i] += occurs[j];
      }
    }
  }
}
int main() {
  int n, m;
  scanf("%d", &n);
  vv.resize(n);
  int grand = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &vv[i]);
    occurs[vv[i]]++;
    grand = max(grand, vv[i]);
  }
  sieve();
  scanf("%d", &m);
  int l, r;
  for (int i = 1; i <= 10000000; i++) {
    cumul[i] = cumul[i - 1] + fp[i];
  }
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &l, &r);
    l = min(l, 10000000);
    r = min(r, 10000000);
    printf("%d\n", cumul[r] - cumul[l - 1]);
  }
  return 0;
}
