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
from bisect import *
from collections import *

INF = 1e9
Input = []
MOD = 1000000007

#sys.stdin = open('in', 'r')
#sys.stdout = open('out', 'w')

def Out(x):
    sys.stdout.write(str(x) + '\n')

def In():
    return sys.stdin.readline().strip()

def inputGrab():
    for line in sys.stdin:
        Input.extend(map(str, line.strip().split()))

############################################################

isPrime = [True for i in range(6150)]
primes = []
divCount = {}

def sieve(lim = 6100):
    global isPrime
    global primes
    
    isPrime[0] = isPrime[1] = 0
    for i in range(2, lim):
        if isPrime[i]:
            primes.append(i)
            for j in range(i+i, lim, i):
                isPrime[j] = 0


def factorize(val):
    global primes
    global divCount
    
    for prime in primes:
        if val < prime:
            break
        if val % prime == 0:
            divCount[prime] += 1
        while val >= prime and val % prime == 0:
            val /= prime
    if val != 1:
        primes.append(val)
        if val not in divCount:
            divCount[val] = 1
        else:
            divCount[val] += 1



def main():
    n = int(In())
    v = map(int, In().split())
    global divCount
    global primes
    
    sieve(50)

    # Key value mapping
    for prime in primes:
        divCount[prime] = 0

    # factorize
    for elem in v:
        factorize(elem)

    
    past = 0
    #print("before cSum")
    #for key, value in divCount.items():
     #   print(key, value)

    
    divCount = OrderedDict(sorted(divCount.items()))
    # Cumulative frequency
    past = 0
    for key, value in divCount.items():
        past += value
        divCount[key] = past

    #print("After cSum")
    #for key, value in divCount.items():
    #    print(key, value)
    
    # Prime Number print
    #for elem in primes:
    #    print(elem, end = ' ')
    #print()

    q = int(In())
    for i in range(q):
        l, r = map(int, In().split())
        #print("-----------------------------------------\n", l, r)
        lftPoint = bisect_right(primes, l)-1
        rhtPoint = bisect_right(primes, r)-1
        #print("First", lftPoint, rhtPoint)
        
        #print("Boundary", primes[rhtPoint], "found", l)
        
        if lftPoint == len(primes) or primes[rhtPoint] < l:
            print('0')
            continue
        elif lftPoint != 0 and primes[lftPoint] != l:
            lftPoint -= 1
        
        
        
        ans = divCount[primes[rhtPoint]]
        #print(primes[rhtPoint])
        if lftPoint != 0:
            #print(primes[lftPoint-1])
            ans -= divCount[primes[lftPoint-1]]
        
        print(ans)
        
        
    
if __name__ == '__main__':
    main()
