#include <bits/stdc++.h>
using namespace std;
int AP[10000005 + 5];
int P[10000005 + 5];
void definep() {
  for (int i = 0; i <= 10000005; i++) {
    P[i] = -1;
  }
  for (int i = 2; i * i <= 10000005; i++) {
    if (P[i] == -1) {
      for (int j = i * i; j <= 10000005; j += i) {
        P[j] = i;
      }
    }
  }
}
void primefact(int n) {
  while (1) {
    if (P[n] == -1) {
      AP[n]++;
      return;
    }
    int p = P[n];
    AP[p]++;
    while (n % p == 0) n /= p;
    if (n == 1) return;
  }
}
long long AC[10000005 + 5];
int l[50000 + 5], r[50000 + 5];
int main() {
  int X;
  int i, j, m, n, resp = 0;
  definep();
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> X;
    primefact(X);
  }
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> l[i];
    cin >> r[i];
  }
  AC[1] = 0;
  for (i = 2; i < 10000005; i++) {
    AC[i] = AC[i - 1] + AP[i];
  }
  for (j = 0; j < m; j++) {
    l[j] = min(l[j], 10000001);
    r[j] = min(r[j], 10000001);
    cout << AC[r[j]] - AC[l[j] - 1] << endl;
  }
}
