#include <bits/stdc++.h>
using namespace std;
const long double pi = 2 * acos(0.0);
template <class T>
bool umin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool umax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class TT>
bool pal(T a, TT n) {
  int k = 0;
  for (int i = 0; i <= n / 2; i++) {
    if (a[i] != a[n - i - 1]) {
      k = 1;
      break;
    }
  }
  return k ? 0 : 1;
}
int a[222222 * 5], c[10000022], p[10000011], d[10000011];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i], c[a[i]]++;
  p[1] = 1;
  for (int i = 2; i <= 10000000; i++) {
    if (p[i]) continue;
    d[i] = c[i];
    for (int j = 2; j * i <= 10000000; j++) {
      d[i] += c[j * i];
      p[i * j] = 1;
    }
  }
  for (int i = 1; i <= 10000000; i++) d[i] += d[i - 1];
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    int ans = 0;
    r = min(r, 10000000);
    if (l > 10000000)
      ans = 0;
    else
      ans = d[r] - d[l - 1];
    cout << ans << '\n';
  }
  getchar();
  getchar();
  return 0;
}
