#include <bits/stdc++.h>
using namespace std;
void fast() {
  cin.tie(0);
  cout.tie(0);
  cin.sync_with_stdio(0);
}
long long numOfDigits(long long n);
bool compare(int &a, int &b) { return a > b; }
long long pow(long long a, long long b);
double BN();
int n;
vector<bool> sieve(1e7 + 1, 1);
int freq[(long long)1e7 + 5];
long long pre[(long long)1e7 + 1] = {0};
int main() {
  fast();
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    freq[a]++;
  }
  sieve[0] = sieve[1] = 0;
  for (long long i = 2; i <= 1e7; i++) {
    if (sieve[i]) {
      long long k = i;
      while (k <= 1e7) sieve[k] = 0, pre[i] += freq[k], k += i;
    }
  }
  for (int i = 1; i < 1e7 + 1; i++) pre[i] += pre[i - 1];
  int m;
  cin >> m;
  while (m--) {
    long long l, r;
    cin >> l >> r;
    l = min(l, (long long)1e7);
    r = min(r, (long long)1e7);
    cout << max(0LL, pre[r] - pre[l - 1]) << "\n";
    ;
  }
  return 0;
}
long long pow(long long a, long long b) {
  long long pow = 1;
  for (int i = 0; i < b; i++) pow *= a;
  return pow;
}
long long numOfDigits(long long n) {
  if (!n) return 1;
  return (long long)(log10(n) + 1);
}
