#973
Unrated
PROGRAM
시간 제한
5s
메모리 제한
32MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Mirko is trying to debug a piece of his code. First he creates an array of N integers and fills it with zeros. Then he repeatedly calls the following procedure (he is such a good coder he coded it in both C++ and Pascal): void something( int jump ) { int i = 0; while( i < N ) { seq[i] = seq[i] + 1; i = i + jump; } } procedure something( jump: longint ); var i : longint; begin i := 0; while i < N do begin seq[i] := seq[i] + 1; i := i + jump; end; end; As you can see, this procedure increases by one all elements in the array whose indices are divisible by jump. Mirko calls the procedure exactly K times, using the sequence X1 X2 X3... Xk as arguments. After this, Mirko has a list of Q special parts of the array he needs to check to verify that his code is working as it should be. Each of this parts is defined by two numbers, L and R (L ≤R) the left and right bound of the special part. To check the code, Mirko must compute the sum of all elements of seq between and including L and R. In other words seq[L] + seq[L+1] + seq[L+2] + ... + seq[R]. Since he needs to know the answer in advance in order to check it, he asked you to help him.

입력

The first line of input contains two integers, N (1 ≤N ≤106), size of the array, and K (1 ≤K ≤ 106), number of calls to something Mirko makes.

The second line contains K integers: X1X2X3 ... Xk, arguments passed to the procedure. (1 ≤Xi < N). Next line contains one integer Q (1 ≤Q ≤106), number of special parts of the array Mirko needs to check. Next Q lines contain two integers each Li i Ri(0 ≤Li≤Ri < N), bounds of each special part.

출력

The output should contain exactly Q lines. The ith line should contain the sum of elements seq[Li] + seq[Li+1] + seq[Li+2] + ... + seq[Ri].

예제 입력 1

10 4
1 1 2 1
3
0 9
2 6
7 7

예제 출력 1

35
18
3

예제 입력 2

11 3
3 7 10
3
0 10
2 6
7 7

예제 출력 2

8
2
1

예제 입력 3

1000000 6
12 3 21 436 2 19
2
12 16124
692 29021

예제 출력 3

16422
28874
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.