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
def isPrime(a):
    if (a <= 1):
        return 0
 
    for i in range(2,math.floor(math.sqrt(a)+1)):
    # for (int i = 2; i <=sqrt(n); i++)
        if (a % i == 0):
            return 0
    return 1

def nextPrime(N): 
    # // Base case
    if (N <= 1):
        return 2
    # print(N)
    prime = N
    found = 0
 
    # // Loop continuously until isPrime returns
    # // true for a number greater than n
    while (found==0):
        prime+=1
        if (isPrime(prime)):
            found = 1
 
    return prime

n=int(input())
count=[0]*100
s=input().split(' ')
for i in range(n):
    count[int(s[i])]+=1

primes=[2]
while primes[-1]<10000000:
    primes.append(nextPrime(primes[-1]))

value=[0]*10000001
for i in primes:
    k=1
    while k*i<1000000001:
        value[i]+=count[k*i]
        k+=1

m=int(input())
for i in range(m):
    a=[int(x) for x in input().split(' ')]
    ans=0
    for j in range(a[0],a[1]+1):
        ans+=value[j]
    print(ans)


 
