Recently, the bear started studying data structures and faced the following problem.

You are given a sequence of integers *x*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub>, ..., *x*<sub class="lower-index">*n*</sub> of length *n* and *m* queries, each of them is characterized by two integers *l*<sub class="lower-index">*i*</sub>, *r*<sub class="lower-index">*i*</sub>. Let's introduce *f*(*p*) to represent the number of such indexes *k*, that *x*<sub class="lower-index">*k*</sub> is divisible by *p*. The answer to the query *l*<sub class="lower-index">*i*</sub>, *r*<sub class="lower-index">*i*</sub> is the sum: <img align="middle" class="tex-formula" src="https://espresso.codeforces.com/5e448f6c1a0e40843cecdbbeb95970464626032f.png" style="max-width: 100.0%;max-height: 100.0%;"/>, where *S*(*l*<sub class="lower-index">*i*</sub>, *r*<sub class="lower-index">*i*</sub>) is a set of prime numbers from segment [*l*<sub class="lower-index">*i*</sub>, *r*<sub class="lower-index">*i*</sub>] (both borders are included in the segment).

Help the bear cope with the problem.
The first line contains integer *n* (1 ≤ *n* ≤ 10<sup class="upper-index">6</sup>). The second line contains *n* integers *x*<sub class="lower-index">1</sub>, *x*<sub class="lower-index">2</sub>, ..., *x*<sub class="lower-index">*n*</sub> (2 ≤ *x*<sub class="lower-index">*i*</sub> ≤ 10<sup class="upper-index">7</sup>). The numbers are not necessarily distinct.

The third line contains integer *m* (1 ≤ *m* ≤ 50000). Each of the following *m* lines contains a pair of space-separated integers, *l*<sub class="lower-index">*i*</sub> and *r*<sub class="lower-index">*i*</sub> (2 ≤ *l*<sub class="lower-index">*i*</sub> ≤ *r*<sub class="lower-index">*i*</sub> ≤ 2·10<sup class="upper-index">9</sup>) — the numbers that characterize the current query.
from sys import stdin
import sys
from bisect import bisect_left, bisect_right
import copy
sys.setrecursionlimit(15000)
 
def get_prime():
    seive = [False] * (10** 7 + 1)
    for i in range(2, 10 ** 7):
        if seive[i] == False:
            for j in range(i * i, 10 ** 7 + 1, i):
                seive[j] = True

    prime = []
    for i in range(2, 10 ** 7):
        if seive[i] == False:
            prime.append(i)
    return prime
 

def get_function(prime, arr, n):
	flag = [0] * (arr[-1]+ 1)
	for i in arr:
		flag[i] += 1
	f_p = [0] * (10 ** 7 + 1)
	for i in range(len(prime)):
		for j in range(prime[i], arr[-1]+ 1, prime[i]):
			if flag[j] > 0 and j % prime[i] == 0:
				f_p[prime[i]] += flag[j]
	return f_p
 

def cummulate(f_p):
	c_f_p = [0] * len(f_p)
	cur_sum = 0
	for i in range(2, len(f_p)):
		c_f_p[i] = f_p[i] + c_f_p[i - 1]
	return c_f_p
 

def binary_search(arr, element, start, end):
	if start > end:
		return -1
	mid = (start + end) // 2
	if arr[mid] == element:
		return mid
	elif arr[mid]< element:
		return binary_search(arr, element, mid + 1, end)
	else:
		return binary_search(arr, element, start, mid - 1)
 
 
prime = get_prime()
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
 
f_p = get_function(prime, arr, n)
c_f_p = cummulate(f_p)
 
m = int(input())
for _ in range(m):
	l, r = list(map(int, input().split()))
	if r > 10 ** 7:
		r = 10 ** 7
	if l > 10 ** 7:
		print(0)
		continue
	
	print(c_f_p[r] - c_f_p[l - 1])