#include <bits/stdc++.h>
using namespace std;
const long long N = 1e7 + 5;
long long n;
long long a[N], f[N];
bool sieve[N];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    f[a[i]]++;
  }
  fill(sieve, sieve + N, 1);
  for (long long i = 2; i < N; i++) {
    if (sieve[i]) {
      for (long long j = 2; i * j < N; j++) {
        f[i] += f[i * j];
        sieve[i * j] = 0;
      }
    }
  }
  for (long long i = 0; i < N; i++) {
    if (!sieve[i]) f[i] = 0;
    f[i] += f[i - 1];
  }
  long long q;
  cin >> q;
  while (q--) {
    long long a, b;
    cin >> a >> b;
    b = min(b, N - 1);
    a = min(a, N);
    long long ans = f[b] - f[a - 1];
    cout << ans << "\n";
  }
}
