#SGM0000009. Đàn kiến (Ant Colony)

Đàn kiến (Ant Colony)

Ant Colony

Source: Codeforces

Version: Phuoc Hung OJ Extended

There are NN ants in a row. Ant ii has strength sis_i. For a query segment [l,r][l,r], every pair of ants in the segment fights. Ant ii receives one point against ant jj if sis_i divides sjs_j.

An ant is freed only if it scores a point in every fight it participates in, i.e. exactly r−lr-l points. All other ants are eaten.

For each query, print the number of ants that are eaten.

Input

The first line contains NN.

The second line contains s1,s2,…,sNs_1,s_2,\ldots,s_N.

The third line contains QQ.

Each of the next QQ lines contains l,rl,r.

Output

Print the number of eaten ants for every query.

Subtasks

  • Subtask 1 — 20%: 1≤N,Q≤501\le N,Q\le 50, 1≤si≤1041\le s_i\le 10^4.
  • Subtask 2 — 30%: 1≤N,Q≤50001\le N,Q\le 5000, 1≤si≤1091\le s_i\le 10^9.
  • Subtask 3 — 50%: 1≤N,Q≤1051\le N,Q\le 10^5, 1≤si≤1091\le s_i\le 10^9.

Examples

Input

5
1 3 2 4 2
4
1 5
2 5
3 5
4 5

Output

4
4
1
1

Explanation

The sample follows the operations exactly; each printed line corresponds to a query that requires output.