Mirko is trying to debug a piece of his code. First he creates an array of integers and fills it with zeros. Then he repeatedly calls the following procedure:
void something( int jump ) {
int i = 0;
while( i < N ) {
seq[i] = seq[i] + 1;
i = i + jump;
}
}
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 times, using the sequence as arguments.
After this, Mirko has a list of special parts of the array he needs to check to
verify that his code is working as it should be. Each of these parts is defined by
two numbers, and 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 and . In other words .
Since he needs to know the answer in advance in order to check it,
he asked you to help him.
Input Specification
The first line of input contains two integers, , size of the array, and , number of calls to something Mirko makes.
The second line contains integers: , arguments passed to the procedure.
Next line contains one integer , number of special parts of the array Mirko needs to check.
Next lines contain two integers each and , bounds of each special part.
Output Specification
The output should contain exactly lines. The th line should contain the sum of elements .
Sample Input 1
10 4
1 1 2 1
3
0 9
2 6
7 7
Sample Output 1
35
18
3
Explanation for Sample Output 1
The procedure is called with arguments , , , . After that, the array contains values . Sum of indices to (inclusive) is .
Sample Input 2
11 3
3 7 10
3
0 10
2 6
7 7
Sample Output 2
8
2
1
Explanation for Sample Output 2
The array is .
Sample Input 3
1000000 6
12 3 21 436 2 19
2
12 16124
692 29021
Sample Output 3
16422
28874
Comments