#include <bits/stdc++.h>
using namespace std;
int const N = 1e6 + 5, SEG = 1 << 21;
int n;
long long arr[N * 10];
int m;
vector<int> primes;
bool isnotpr[N * 10];
long long sum[N * 10];
void sieve() {
  isnotpr[0] = 1;
  isnotpr[1] = 1;
  for (int i = 2; i < N * 10; i++) {
    if (!isnotpr[i]) {
      primes.push_back(i);
      sum[i] += arr[i];
      for (int ii = 2; ii * i < N * 10; ii++) {
        isnotpr[ii * i] = 1;
        sum[i] += arr[i * ii];
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  long long x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    arr[x]++;
  }
  sieve();
  for (int i = 1; i < N * 10; i++) {
    sum[i] += sum[i - 1];
  }
  int m;
  cin >> m;
  int a, b;
  while (m--) {
    cin >> a >> b;
    a = min(a, (N * 10) - 2);
    b = min(b, (N * 10) - 2);
    cout << sum[b] - sum[a - 1] << endl;
  }
  return 0;
}
