#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.1415926535898;
const long long INF = LLONG_MAX;
const long long MOD = 1000000007;
int first[(int)1e7 + 5] = {0};
long long dp[(int)1e7 + 5] = {0};
void precalculate() {
  first[1] = 1;
  for (int i = 2; i < (int)1e7 + 5; i++) {
    if (first[i]) continue;
    for (int j = i; j < (int)1e7 + 5; j += i) {
      if (first[j] == 0) first[j] = i;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  precalculate();
  int x[n];
  for (int i = 0; i < n; i++) cin >> x[i];
  for (int i = 0; i < n; i++) {
    int prev = 1;
    while (x[i] != 1) {
      if (first[x[i]] != prev) dp[first[x[i]]]++;
      prev = first[x[i]];
      x[i] /= first[x[i]];
    }
  }
  for (int i = 3; i < (int)1e7 + 5; i++) dp[i] += dp[i - 1];
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    l = min(l, (int)1e7 + 1);
    r = min(r, (int)1e7 + 1);
    cout << dp[r] - dp[l - 1] << "\n";
  }
}
