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.
import math
'''primes = False
def generate_primes(n):
	global primes
	a=[True]*(n+1)
	a[0] = a[1] = False
	for i in range(2,int(math.sqrt(n))+1):
		if a[i]:
			for j in range(i**2,n+1,i):
				a[j]=False
	primes = set([i for i,v in enumerate(a) if v])

if __name__ == '__main__':
	generate_primes(2000000000)
	n=int(input())
	x = list(map(split(input()),int))
	m = int(input())
	for i in range(m):
		p = []
		l,r = list(map(split(input()),int))
		for i in range(l,r+1):
			if i in primes:
				p.append(i)
		total = 0
		for ep in p:
			for ex in x:
				if ex%ep == 0:
					total+=1
		print(total)'''

if __name__ == '__main__':
	n=int(input())
	#x = [v for v in map(input().split(),int)]
	x = list(map(int,input().split()))
	m = int(input())
	p= {}
	for ex in x:
		limit = int(math.sqrt(ex))
		i=2
		up = set()
		while i <= limit:
			if ex%i == 0:
				up.add(i)
				ex = ex/i
				if(ex == 1):
					break
			else:
				i+=1
		else:
			up.add(ex)
		for e in up:
			p[e] = p[e]+1 if e in p else 1

	for i in range(m):
		total = 0
		l,r = list(map(int,input().split()))

		for kp in p:
			if kp >= l and kp <= r:
				total+=p[kp]
		print(total)

