#include <bits/stdc++.h>
using namespace std;
int n;
int c[10001000], a[10001000];
bool marked[10001000];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  memset(c, 0, 10001000);
  memset(a, 0, 10001000);
  memset(marked, false, 10001000);
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    c[t]++;
  }
  for (int i = 2; i < 10001000; i++) {
    if (marked[i]) continue;
    for (int j = i; j < 10001000; j += i) {
      marked[j] = true;
      a[i] += c[j];
    }
  }
  for (int i = 1; i < 10001000; i++) {
    a[i] += a[i - 1];
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    l = min(l, 10001000 - 1);
    r = min(r, 10001000 - 1);
    cout << a[r] - a[l - 1] << "\n";
  }
}
