Aladin was walking down the path one day when he found the strangest thing.
- Set the number of stones in the box labeled
to modulo . - It proceeds to fly to the box labeled
, and set the number of stones there to . - It proceeds to fly to the box labeled
, and set the number of stones there to . - Generally, it visits each box labeled between
and , and set the number of stones there to , where is the box label. - After it visits the box labeled
. It settles down for further instructions.
During the game Aladin wonders what is the total number of stones in some range of boxes.
Write a program that simulates the device and answers Aladin's questions.
Input Specification
The first line contains two integers
The next
If the line starts with 1 L R A B
If the line starts with 2 L R
Output Specification
For each query beginning with
Scoring
Test cases worth
Test cases worth
Sample Input 1
6 3
2 1 6
1 1 5 1 2
2 1 6
Sample Output 1
0
3
Explanation for Sample Output 1
The boxes start containing
After that the device sets the stones to
Sample Input 2
4 5
1 1 4 3 4
2 1 1
2 2 2
2 3 3
2 4 4
Sample Output 2
3
2
1
0
Sample Input 3
4 4
1 1 4 7 9
2 1 4
1 1 4 1 1
2 1 4
Sample Output 3
16
0
Comments