luogu#P5190. [COCI 2009/2010 #5] PROGRAM

[COCI 2009/2010 #5] PROGRAM

Problem Description

Translated from COCI 2010.03.06 T5 “PROGRAM”.

At the beginning, the array seq\mathit{seq} is all zeros. Note that the first element of seq\mathit{seq} has index 0, not 1.

void something (int jump) {
  for (int i = 0; i < N; i += jump)
    ++seq[i];
}

Mirko called the function something\tt something exactly KK times. In the ii-th call, jump=Xi\tt jump = \it X_i.

Then there are QQ queries. Each query contains two integers Li,L_i, RiR_i. For each query, output i=LiRiseqi\displaystyle\sum_{i=L_i}^{R_i}\mathit{seq}_i.

Input Format

The first line contains N,KN, K.
The next line contains KK integers, where the ii-th one is XiX_i.
Line N+2N + 2 contains QQ.
The next QQ lines each contain two integers Li,L_i, RiR_i.

Output Format

Output QQ lines. The ii-th line contains the answer to the ii-th query.

10 4
1 1 2 1
3
0 9
2 6
7 7
35
18
3
11 3
3 7 10
3
0 10
2 6
7 7
8
2
1
1000000 6
12 3 21 436 2 19
2
12 16124
692 29021
16422
28874

Hint

Sample Explanation 1

seq={4,3,4,3,4,3,4,3,4,3}seq=\{4, 3, 4, 3, 4, 3, 4, 3, 4, 3\}

Sample Explanation 2

seq={3,0,0,1,0,0,1,1,0,1,1}seq=\{3, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1\}

Constraints

1N,K,Q106,1 \le N, K, Q \le 10^6, 1Xi<N,1 \le X_i < N, 0LiRi<N0 \le L_i \le R_i < N.

Translated by ChatGPT 5