#include <bits/stdc++.h>
using namespace std;
int n, m;
int brd = 10000010, ctr[10001000], prf_sum[10100000], ex_cnt[10100000];
bool prm[10100000];
void calc() {
  for (int i = 0; i <= brd; ++i) prm[i] = true;
  prm[0] = false;
  prm[1] = false;
  for (int sti = 2; sti <= brd; ++sti) {
    if (!prm[sti]) continue;
    ex_cnt[sti] += ctr[sti];
    for (int ml = 2; ml * sti <= brd; ++ml) {
      ex_cnt[sti] += ctr[ml * sti];
      prm[ml * sti] = false;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int v;
    scanf("%d", &v);
    ++ctr[v];
  }
  calc();
  prf_sum[0] = 0;
  prf_sum[1] = 0;
  for (int i = 0; i <= brd + 5; ++i) {
    prf_sum[i] = prf_sum[i - 1] + ex_cnt[i];
  }
  scanf("%d", &m);
  for (int qi = 0; qi < m; ++qi) {
    int l, r;
    scanf("%d%d", &l, &r);
    if (l > brd) l = brd;
    if (r > brd) r = brd;
    int ans = prf_sum[r] - prf_sum[l - 1];
    printf("%d\n", ans);
  }
}
