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.
def main(inp):
    n = int(inp())
    xs = split_inp_int(inp)
    m = int(inp())
    queries = [split_inp_int(inp) for __ in range(m)]

    max_num = 10000001
    # step 1
    count = [0] * max_num
    for x in xs:
        count[x] += 1

    # step 2
    prime = [True] * max_num
    f = [0] * max_num
    for i in range(2, max_num):
        if prime[i]:
            for j in range(i*i, max_num, i):
                prime[j] = False

            total = 0
            for j in range(i, max_num, i):
                total += count[j]
            f[i] = total

    # step 3
    partial = [0] * max_num
    for i in range(2, max_num):
        partial[i] = partial[i-1] + f[i]

    # step 5
    for l, r in queries:
        print(partial[r] - partial[l-1])

def split_inp_int(inp):
    return list(map(int, inp().split()))


def use_fast_io():
    import sys

    class InputStorage:
        def __init__(self, lines):
            lines.reverse()
            self.lines = lines

        def input_func(self):
            if self.lines:
                return self.lines.pop()
            else:
                return ""

    input_storage_obj = InputStorage(sys.stdin.readlines())
    return input_storage_obj.input_func


from collections import Counter, defaultdict
from functools import reduce
import operator
import math


def product(arr_):
    return reduce(operator.mul, arr_, 1)

if __name__ == "__main__":

    main(use_fast_io())
