#include <bits/stdc++.h>
using namespace std;
clock_t _start_clock = clock();
inline void _time() {}
inline int log(const char* format, ...) { return 0; }
const double EPS = 10e-8;
const int MAX = 1000010;
const int MX = 10 * MAX;
const int INF = 1 << 30;
int X[MAX];
long long F[MX];
long long S[MX];
bool sieve[MX];
int C[MX];
vector<int> primes;
void init() {
  int i, j;
  int sr = sqrt(MX);
  primes.push_back(0);
  for (i = 2; i < sr; i++) {
    if (!sieve[i])
      for (j = i * i; j < MX; j += i) sieve[j] = true;
  }
  for (i = 2; i < MX; i++)
    if (!sieve[i]) primes.push_back(i);
}
int find_left(int n) {
  int low = 1, high = primes.size(), mid;
  while (low < high) {
    mid = (low + high) / 2;
    if (primes[mid] < n)
      low = mid + 1;
    else
      high = mid;
  }
  return (low == int(primes.size())) ? -1 : low;
}
int find_right(int n) {
  int low = 1, high = primes.size() - 1, mid;
  while (low < high) {
    mid = (low + high + 1) / 2;
    if (primes[mid] > n)
      high = mid - 1;
    else
      low = mid;
  }
  return high;
}
int main(int argc, char** argv) {
  int n, m, i, j;
  init();
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &X[i]);
    C[X[i]]++;
  }
  int size = primes.size();
  for (i = 1; i < size; i++) {
    int p = primes[i];
    for (j = p; j < MX; j += p) {
      F[i] += C[j];
    }
  }
  for (i = 1; i < size; i++) S[i] = S[i - 1] + F[i];
  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    int l, r;
    scanf("%d %d", &l, &r);
    int a = find_left(l);
    int b = find_right(r);
    long long ans = 0;
    if (a != -1) {
      if (a == b) {
        if ((primes[a] == l) || (primes[b] == r) ||
            (l < primes[a] && primes[a] < r))
          ans = S[b] - S[a - 1];
      } else {
        ans = S[b] - S[a - 1];
      }
    }
    cout << ans << endl;
  }
  return EXIT_SUCCESS;
}
