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.
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

void prime(int n, vector <int> &p)
{
	int i, j, k = n + 1, m = int(sqrt(n)) + 1;

	vector <int> t(k, 1);
	p.push_back(2);

	for(i = 3; i < m; i++) if(t[i]) for(j = i * i; j < k; j += 2 * i) t[j] = 0;
	for(i = 3; i < k; i += 2) if(t[i]) p.push_back(i);
}

void main()
{
	int i, j, k, n = 1000001;
	int l, r;
	vector <int> ::iterator a, b;

	vector <int> p;
	vector <int> t(n, 0);

	prime(n, p);
	vector <int> s(p.size() + 1);

	cin >> k;
	for(i = 0; i < k; i++) {
		cin >> j;
		t[j] += 1;
	}
	for(i = 0; i < p.size(); i++) for(j = p[i]; j < n; j += p[i]) s[i + 1] += t[j];
	for(i = 0; i < p.size(); i++) s[i + 1] += s[i];

	cin >> k;
	for(i = 0; i < k; i++) {
		cin >> l >> r;
		l = lower_bound(p.begin(), p.end(), l) - p.begin();
		r = upper_bound(p.begin(), p.end(), r) - p.begin();
		cout << s[r] - s[l];
	}
}