#include <bits/stdc++.h>
using namespace std;
int n, m, a[1000005], p[1000005], num[10 * 1000005], cnt, maxx, s[1000005];
bool vis[10 * 1000005];
void init() {
  for (int i = 2; i <= maxx; i++) {
    if (!vis[i]) p[++cnt] = i;
    for (int j = 1; j <= cnt && p[j] * i <= maxx; j++) {
      vis[p[j] * i] = 1;
      if (i % p[j] == 0) break;
    }
  }
  for (int i = 1; i <= cnt; i++) {
    for (int j = 1; j * p[i] <= maxx; j++) s[i] += num[j * p[i]];
    s[i] += s[i - 1];
  }
}
int find(int x) {
  int left = 1, right = cnt, mid;
  while (left < right) {
    mid = (left + right) / 2;
    if (p[mid] == x) return mid;
    if (p[left] == x) return left;
    if (p[right] == x) return right;
    if (p[mid] > x)
      right = mid;
    else
      left = mid;
    if (p[mid] <= x && x < p[mid + 1]) return mid;
    if (p[left] <= x && x < p[left + 1]) return left;
    if (p[right] <= x && x < p[right + 1]) return right;
  }
}
int main() {
  int L, R, x, y;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    maxx = max(a[i], maxx);
    num[a[i]]++;
  }
  init();
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d", &L, &R);
    if (L > maxx) {
      printf("0\n");
      continue;
    }
    x = lower_bound(p + 1, p + cnt + 1, L) - p;
    y = upper_bound(p + 1, p + cnt + 1, R) - p - 1;
    printf("%d\n", s[y] - s[x - 1]);
  }
  return 0;
}
