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 collections import defaultdict

def counstruc_seive(limit = int(1e7)):
	seive = dict()
	
	for i in range(2, limit+1):
		if i not in seive:
			x = 1
			
			while x*i <= limit:
				seive[x*i] = i
				x += 1

	return seive

def factorise(num, seive):
	factors = set()

	while num > 1:
		factors.add(seive[num])
		num /= seive[num]

	return factors

if __name__ == '__main__':
	n = int(input())
	sequence = [int(x) for x in input().split()]

	seq_max = max(sequence)
	seive = counstruc_seive(seq_max)
	factor_freq = defaultdict(int)

	for i in sequence:
		factors = factorise(i, seive)
		for j in factors:
			factor_freq[j] += 1
	
	curr_sum = 0
	cum_fact_freq = defaultdict(int)
	
	prime_factors = sorted(factor_freq.keys())
	for i in range(seq_max+1):
		cum_fact_freq[i] = curr_sum + factor_freq[i]
		curr_sum = cum_fact_freq[i] 
	
	# print(cum_fact_freq)	
	m = int(input()) 
		
	while m:
		m  -= 1
		l, r = map(int, input().split())
		r = min(seq_max, r)
		print(cum_fact_freq[r] - cum_fact_freq[l-1])