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.
from collections import defaultdict, deque, Counter
from functools import lru_cache, reduce 
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
from random import randint
from math import * 
import operator
import sys
from itertools import accumulate 
#sys.stdin = open("sleepy.in", "r")
#sys.stdout = open("sleepy.out","w")
#input = sys.stdin.readline
#print = sys.stdout.write
 
hpop = heappop
hpush = heappush
MOD = 10**9 + 7
 
def solution():
    # get prime numbers
    n = int(input())
    arr = list(map(int, input().split()))
    m = int(input())
    
    root = int(sqrt(n)) + 1
    max_num = max(arr)
    count = [0]*(max_num + 1)
    for val in arr:
        count[val] += 1

    # for every prime count
    isprime = [True]*(max_num + 1)
    for i in range(2, root):
        for j in range(i + i, max_num + 1, i):
            isprime[j] = False

    res = [0]*len(isprime)
    # just go untile sqrt()
    for i in range(2, len(res)):
        if isprime[i]:
            for j in range(i, len(count), i):
                res[i] += count[j]

    for i in range(1, len(res)):
        res[i] += res[i-1]

    for _ in range(m):
        l,r = map(int, input().split())
        if l >= len(res): l = -1
        if r >= len(res): r = -1
        
        print(res[r] - res[l-1])
 
def main():
    #test()
    t = 1
    #t = int(input())
    for _ in range(t):
        solution() 
 
#import sys
#import threading
#sys.setrecursionlimit(10**6)
#threading.stack_size(1 << 27)
#thread = threading.Thread(target=main)
#thread.start(); thread.join()
main()
