#include <bits/stdc++.h>
using namespace std;
int arr[10000007], sieve[10000007], sum[10000007];
int main() {
  int n, temp, bada = 0, m, l, r;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &temp);
    if (temp > bada) bada = temp;
    arr[temp]++;
  }
  for (int i = 2; i <= bada; i++) {
    if (sieve[i] == 0) {
      for (int j = i; j <= bada; j += i) {
        sieve[j] = 1;
        if (arr[j] != 0) {
          sum[i] += arr[j];
        }
      }
    }
  }
  for (int i = 1; i <= bada; i++) {
    sum[i] += sum[i - 1];
  }
  scanf("%d", &m);
  while (m--) {
    scanf("%d %d", &l, &r);
    if (r > bada) r = bada;
    if (l > bada) l = bada + 1;
    printf("%d\n", sum[r] - sum[l - 1]);
  }
  return 0;
}
