Good Intervals

Time limit: 0.5s Memory limit: 64MB Input: Output:

Task

For some k1k \ge 1, we say that the sequence of integers v=[v1,v2,vk]v = [v_1, v_2, \ldots v_k] is good if viv_i is divisible by ii for every ii from 11 to kk.

Writing good sequences is a fashionable pastime!\text{Writing good sequences is a fashionable pastime!}

You are given an integer sequence A=[A1,A2,,AN]A = [A_1, A_2, \ldots, A_N] of length NN and QQ queries of the form li,ril_i, r_i, which represent the range of values [Ali,Ali+1,,Ari][A_{l_i}, A_{l_i+1}, \ldots, A_{r_i}] from the sequence.

For each query compute the number of subintervals of the given range which are good sequences (each subinterval is considered as an independent sequence, indexed from 11).

Input data

The first line of the input file contains a single integer TT, the number of test cases. TT test cases follow, each preceded by an empty line.

The first line of each test case contains a single integer NN, the length of the sequence.

The second line of each test case contains NN space-separated integers AiA_i, the elements of the sequence.

The third line of each test case contains a single integer QQ, the number of queries.

Each of the following QQ lines contain two integers li,ril_i, r_i, the query intervals.

Output data

For each test case, output all query results, each on a separate line.

Constraints and clarifications

  • 1T101 \le T \le 10.
  • 1N,Q100 0001 \le N, Q \le 100 \ 000.
  • 1Ai10181 \le A_i \le 10^{18}.
  • 1liriN1 \le l_i \le r_i \le N.
  • The sum of NN and QQ over all test cases does not exceed 100 000100 \ 000.
# Points Constraints
1 0 Examples.
2 10 N,Q200N, Q \le 200
3 20 N2000N \le 2000
4 30 Ai106A_i \le 10^6 for every i=1Ni=1 \ldots N
5 40 No additional limitations.

Example

stdin

1

5
6 24 6 8 10
3
1 3
2 4
1 5

stdout

6
5
12

Explanation

In the sample case, consider the the second query corresponding to the range of values [24,6,8][24, 6, 8].

  • An example of a good subinterval is [A2,A3]=[24,6][A_2, A_3] = [24, 6], because 2424 is divisible by 11 and 66 is divisible by 22.
  • An example of a subinterval which is not good is [A2,A3,A4]=[24,6,8][A_2, A_3, A_4] = [24, 6, 8], as 88 is not divisible by 33.

The 55 good subintervals for this query are the sequences [24][24], [24,6][24, 6], [6][6], [6,8][6, 8] and [8][8].

Log in or sign up to be able to send submissions!