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
n = int(input())
a =[int(i) for i in input().split()]
m = int(input())
primes = [True] * 10**6
primes[0] = False
primes[1] = False
for i in range(2, 10**3):
    if primes[i]:
        for j in range(i * i, 10**6, i):
            primes[j] = False
new_primes = []
index = {}
cnt = 0
for i in range(10**6):
    if primes[i]:
        index[i] = cnt
        new_primes.append(i)
        cnt += 1
mas = [0] * len(new_primes)
for i in a:
    now = i
    for j in range(len(new_primes)):
        if new_primes[j] > now**0.5:
            break
        if now % new_primes[j] == 0:
            while now % new_primes[j] == 0:
                now = now // new_primes[j]
            mas[j] += 1
    if now != 1:
        mas[index[now]] += 1
pref = [0] * (len(mas) + 1)
for i in range(1, len(mas) + 1):
    pref[i] = pref[i - 1] + mas[i - 1]
for i in range(m):
    x,y = map(int, input().split())
    left = bisect.bisect_right(new_primes, x)
    right = bisect.bisect_left(new_primes, y)
    if right == left:
        print(0)
    else:
        print(pref[right] - pref[left - 1])