#include <bits/stdc++.h>
using namespace std;
vector<int> prime;
const int mx = 10000006;
int gg = 0;
vector<long long> isprime(mx), ttl(mx), sum(mx);
int a[1000006];
void sieve() {
  prime.push_back(2);
  isprime[2] = 0;
  for (int i = 3; i * i <= mx; i += 2) {
    if (!isprime[i]) {
      for (int j = i * i; j <= mx; j += i) {
        isprime[j] = 1;
      }
    }
  }
  for (int i = 3; i <= mx; i += 2) {
    if (!isprime[i]) prime.push_back(i);
  }
  for (int i = 0, p = prime[i]; i < prime.size() && p <= mx;
       ++i, p = prime[i]) {
    for (int j = p * 2; j <= mx; j += p) {
      sum[p] += sum[j];
      isprime[j] = 1;
    }
  }
  ttl[0] = ttl[1] = 0;
  for (int i = 2; i <= mx; ++i) {
    if (!isprime[i])
      ttl[i] = ttl[i - 1] + sum[i];
    else
      ttl[i] = ttl[i - 1];
  }
}
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum[a[i]]++;
  }
  sieve();
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    x = min(x, mx);
    y = min(y, mx);
    cout << ttl[y] - ttl[x - 1] << endl;
  }
  return 0;
}
