#include <bits/stdc++.h>
using namespace std;
vector<bool> prime(10000001, true);
void soe() {
  for (int i = 2; i <= 10000000; i++) {
    if (prime[i]) {
      for (int j = 2 * i; j <= 10000000; j += i) {
        prime[j] = false;
      }
    }
  }
}
void solve() {
  vector<int> a(10000000, 0);
  int n;
  cin >> n;
  int x;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    a[x]++;
  }
  vector<int> b(10000000, 0);
  b[0] = 0;
  b[1] = 0;
  for (int i = 2; i <= 10000000; i++) {
    if (prime[i]) {
      for (int j = 1; j * i <= 10000000; j++) {
        b[i] += a[j * i];
      }
    }
  }
  for (int i = 1; i <= 10000000; i++) {
    b[i] += b[i - 1];
  }
  int q;
  cin >> q;
  int u, v;
  while (q--) {
    cin >> u >> v;
    if (u > 10000000) {
      cout << 0 << '\n';
    } else {
      int z = min(10000000, v);
      cout << b[z] - b[u - 1] << '\n';
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin.tie(0);
  int t = 1;
  soe();
  while (t--) solve();
  return 0;
}
