#include <bits/stdc++.h>
int vl[10000003];
long long lst[10000002];
int pr[5002];
int main() {
  int n, m, va, vb;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &m);
    vl[m]++;
  }
  for (int i = 2; i < 5002; i++) pr[i] = 1;
  for (int i = 2; i < 5002; i++)
    if (pr[i])
      for (int j = i + i; j < 5002; j += i) pr[j] = 0;
  for (int i = 2; i < 5002; i++) {
    if (pr[i]) {
      for (int j = i; j < 10000001; j += i) {
        int k = j;
        while (k % i == 0) k /= i;
        lst[i] += vl[j];
        vl[k] += vl[j];
        vl[j] = 0;
      }
    }
  }
  for (int i = 2; i < 10000001; i++) lst[i] += vl[i];
  for (int i = 1; i < 10000001; i++) lst[i] += lst[i - 1];
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &va, &vb);
    if (vb > 10000000) vb = 10000000;
    if (va > 10000000) va = 10000000;
    printf("%I64d\n", lst[vb] - lst[va - 1]);
  }
  return 0;
}
