#include <bits/stdc++.h>
using namespace std;
vector<int> prime;
bitset<10000010> bs;
void sieve() {
  bs.set();
  for (long long int i = 2; i < 10000000; i++) {
    if (bs[i]) {
      prime.push_back(i);
      for (long long int j = i * i; j < 10000000; j += i) {
        bs[j] = 0;
      }
    }
  }
}
int cont;
int mp[10001000];
void fac(int val) {
  int k = 0;
  while (prime[k] * prime[k] <= val) {
    bool tr = false;
    while (val % prime[k] == 0) {
      tr = true;
      val /= prime[k];
    }
    if (tr) mp[prime[k]]++;
    k++;
  }
  if (val != 1) mp[val]++;
}
long long int sum[10010000];
int main() {
  int n, val, m;
  long long int l, r;
  sieve();
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &val);
    fac(val);
  }
  for (int i = 1; i <= 9999991; i++) {
    sum[i] = sum[i - 1] + mp[i];
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%lld%lld", &l, &r);
    if (l > 9999991)
      printf("0\n");
    else {
      if (r > 9999991) r = 9999991;
      printf("%lld\n", sum[r] - sum[l - 1]);
    }
  }
}
