CF474F.Ant colony

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Mole is hungry again. He found one ant colony, consisting of nn ants, ordered in a row. Each ant ii ( 1<=i<=n1<=i<=n ) has a strength sis_{i} .

In order to make his dinner more interesting, Mole organizes a version of «Hunger Games» for the ants. He chooses two numbers ll and rr ( 1<=l<=r<=n1<=l<=r<=n ) and each pair of ants with indices between ll and rr (inclusively) will fight. When two ants ii and jj fight, ant ii gets one battle point only if sis_{i} divides sjs_{j} (also, ant jj gets one battle point only if sjs_{j} divides sis_{i} ).

After all fights have been finished, Mole makes the ranking. An ant ii , with viv_{i} battle points obtained, is going to be freed only if vi=rlv_{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 tt segments [li,ri][l_{i},r_{i}] and asks for each of them how many ants is he going to eat if those ants fight.

输入格式

The first line contains one integer nn (1n1051 ≤ n ≤ 10^5), the size of the ant colony.

The second line contains nn integers s1,s2,,sns_1, s_2, \ldots, s_n (1si1091 ≤ s_i ≤ 10^9), the strengths of the ants.

The third line contains one integer tt (1t1051 ≤ t ≤ 10^5), the number of test cases.

Each of the next tt lines contains two integers lil_i and rir_i (1lirin1 ≤ l_i ≤ r_i ≤ n), describing one query.

输出格式

Print to the standard output tt lines. The ii-th line contains number of ants that Mole eats from the segment [li,ri][l_i, r_i].

输入输出样例

  • 输入#1

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

    输出#1

    4
    4
    1
    1
    

说明/提示

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

In the second test case battle points are v=[0,2,0,2]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]v = [2, 0, 2], so ants number 33 and 55 are freed. Mole eats only the ant 44.

In the fourth test case battle points are v=[0,1]v = [0, 1], so ant number 55 is freed. Mole eats the ant 44.

首页