#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[1100000];
long long num[11000000];
int prim[4000], cnt = 0;
bool f[4000];
void pre() {
  memset(f, 0, sizeof(f));
  for (int i = 2; i <= 4000; i++)
    if (f[i] == 0) {
      prim[cnt] = i;
      cnt++;
      for (int j = 2; j * i <= 4000; j++) f[i * j] = 1;
    }
}
int main() {
  pre();
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    int j = 0;
    while (a[i] > 1 && j < cnt) {
      if (a[i] % prim[j] == 0) num[prim[j]]++;
      while (a[i] % prim[j] == 0) a[i] /= prim[j];
      j++;
    }
    if (a[i] != 1) num[a[i]]++;
  }
  for (int i = 2; i <= 10000000; i++) num[i] += num[i - 1];
  scanf("%d", &m);
  int x, y;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    if (x > 10000000) x = 10000000;
    if (y > 10000000) y = 10000000;
    printf("%lld\n", num[y] - num[x - 1]);
  }
  return 0;
}
