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 sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#arr=list(map(int, input().split()))
def primeFactors(n):
    l=[]
    if(n%2==0):
        l=[2]
    while n % 2 == 0:
        n = n // 2
    p=n**(0.5)
    for i in range(3,int(p)+1,2):
        temp=n
        while n % i== 0:
            n = n // i
        if(temp!=n):
            l.append(i)
    if n>2:
        l.append(n)
    return l
def main():
    n=int(input())
    arr=list(map(int, input().split()))
    l=[0]*((10**7)+1)
    for i in range(n):
        g=primeFactors(arr[i])
        for j in range(len(g)):
            l[g[j]]+=1
    pref=[0]*((10**7)+1)
    for i in range(1,len(pref)):
        pref[i]=pref[i-1]+l[i]
    m=int(input())
    for i in range(m):
        arr=list(map(int, input().split()))
        ls=min(arr[0],10**7)
        rs=min(arr[1],10**7)
        print(pref[rs]-pref[ls]+l[ls])
if __name__ == '__main__':
    main()