#include <bits/stdc++.h>
using namespace std;
int spf[10000001];
void sieve() {
  spf[1] = 1;
  for (int i = 2; i < 10000001; i++) {
    spf[i] = i;
  }
  for (int i = 4; i < 10000001; i += 2) {
    spf[i] = 2;
  }
  for (int i = 3; i * i < 10000001; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < 10000001; j += i)
        if (spf[j] == j) spf[j] = i;
    }
  }
}
vector<int> getFactorization(int x) {
  vector<int> ret;
  while (x != 1) {
    ret.push_back(spf[x]);
    x = x / spf[x];
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sieve();
  vector<int> cnt(10000001);
  for (int i = 0; i < n; i++) {
    vector<int> v = getFactorization(arr[i]);
    for (int j = 0; j < v.size(); j++) {
      if (j == 0 || v[j] != v[j - 1]) {
        cnt[v[j]]++;
      }
    }
  }
  cnt[0] = 0;
  cnt[1] = 0;
  for (int i = 2; i <= 10000000; i++) {
    cnt[i] = cnt[i - 1] + cnt[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    l = min(l, 10000000);
    r = min(r, 10000000);
    cout << cnt[r] - cnt[l - 1] << "\n";
  }
}
