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 bisect
smallestPrimes = [0]+[0,2]*(5000001)
primes = [1,1,0]+[0,1]*(5000001)
for x in range(3163):
    if not primes[x]:
        smallestPrimes[x]=x
        for y in range(x*x,5000002,2*x):
            primes[y]=1
            smallestPrimes[y]=x
allPrimes = []
for x in range(10000001):
    if (not primes[x]):
        allPrimes.append(x)
def getAllprimes(n):
    answer=set([])
    while n>1:
        answer.add(smallestPrimes[n])
        # print (n,smallestPrimes[n])
        n//=smallestPrimes[n]
    return answer

def getAllPrimesDivisibleSum(arr):
    for num in arr:
        for prime in getAllprimes(num):
            # print (prime)
            primes[prime]+=1
    # print (allPrimes[:5])
    # print (primes[:11])
    primesDivisibleSum = [primes[allPrimes[0]]]
    for prime in allPrimes[1:]:
        primesDivisibleSum.append(primesDivisibleSum[-1]+primes[prime])
    return primesDivisibleSum


def solve():
    n = int(input())
    array = list(map(int,input().split()))
    primesDivisbleSums = getAllPrimesDivisibleSum(array)
    # print (primesDivisbleSums[:5])
    m = int(input())
    for _ in range(m):
        l,r = map(int,input().split())
        left = bisect.bisect_left(allPrimes,l)
        right = bisect.bisect_right(allPrimes,min(r,10000000))-1
        ans = primesDivisbleSums[right]
        if (left>0): ans -= primesDivisbleSums[left-1]
        # print (left , right)
        print (ans)

solve()
