Codeforces Round 271 (Div. 2)
F
Ant colony
Codeforces
2100
原题
← E→
翻译中…

Mole is hungry again. He found one ant colony, consisting of $*n*$ ants, ordered in a row. Each ant $*i*$ ($1 ≤ *i* ≤ *n*$) has a strength $*s*_{*i*}$.

翻译中…

In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two numbers $*l*$ and $*r*$ ($1 ≤ *l* ≤ *r* ≤ *n*$) and each pair of ants with indices between $*l*$ and $*r*$ (inclusively) will fight. When two ants $*i*$ and $*j*$ fight, ant $*i*$ gets one battle point only if $*s*_{*i*}$ divides $*s*_{*j*}$ (also, ant $*j*$ gets one battle point only if $*s*_{*j*}$ divides $*s*_{*i*}$).

翻译中…

After all fights have been finished, Mole makes the ranking. An ant $*i*$, with $*v*_{*i*}$ battle points obtained, is going to be freed only if $*v*_{*i*} = *r* - *l*$, or in other words only if it took a point in every fight it participated. After that, Mole eats the rest of the ants. Note that there can be many ants freed or even none.

翻译中…

In order to choose the best sequence, Mole gives you $*t*$ segments $[*l*_{*i*}, *r*_{*i*}]$ and asks for each of them how many ants is he going to eat if those ants fight.

翻译中…

Input

翻译中…

The first line contains one integer $*n*$ ($1 ≤ *n* ≤ 10^{5}$), the size of the ant colony.

翻译中…

The second line contains $*n*$ integers $*s*_{1}, *s*_{2}, ..., *s*_{*n*}$ ($1 ≤ *s*_{*i*} ≤ 10^{9}$), the strengths of the ants.

翻译中…

The third line contains one integer $*t*$ ($1 ≤ *t* ≤ 10^{5}$), the number of test cases.

翻译中…

Each of the next $*t*$ lines contains two integers $*l*_{*i*}$ and $*r*_{*i*}$ ($1 ≤ *l*_{*i*} ≤ *r*_{*i*} ≤ *n*$), describing one query.

翻译中…

Output

翻译中…

Print to the standard output $*t*$ lines. The $*i*$-th line contains number of ants that Mole eats from the segment $[*l*_{*i*}, *r*_{*i*}]$.

翻译中…

Note

翻译中…

In the first test battle points for each ant are $*v* = [4, 0, 2, 0, 2]$, so ant number $1$ is freed. Mole eats the ants $2$, $3$, $4$, $5$.

翻译中…

In the second test case battle points are $*v* = [0, 2, 0, 2]$, so no ant is freed and all of them are eaten by Mole.

翻译中…

In the third test case battle points are $*v* = [2, 0, 2]$, so ants number $3$ and $5$ are freed. Mole eats only the ant $4$.

翻译中…

In the fourth test case battle points are $*v* = [0, 1]$, so ant number $5$ is freed. Mole eats the ant $4$.

翻译中…

样例

Input #1
5
1 3 2 4 2
4
1 5
2 5
3 5
4 5
Output #1
4
4
1
1
InputCopy OutputCopy
题目信息
题号
474F
时间限制
1 s
内存限制
256 MB
标签
数据结构
数学
数论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。