#abc255h. [abc255_h]Range Harvest Query
[abc255_h]Range Harvest Query
Problem Statement
There are trees. On Day , each tree bears no fruits.
On the morning of Day and subsequent days, the -th tree bears new fruits for each .
Takahashi will perform harvesting. For each , the -th harvesting takes place on the night of Day , collecting all fruits remaining on the -th through -th trees at that point.
For each of the harvesting, print the number of fruits Takahashi will collect, modulo .
Constraints
- $1 \\leq D_1 \\lt D_2 \\lt \\cdots \\lt D_Q \\leq 10^{18}$
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print lines. For each , the -th line should contain the number of fruits Takahashi will collect in the -th harvesting, modulo .
Sample Input 1
5 3
2 2 3
3 3 4
5 1 5
Sample Output 1
10
15
50
For each , let be the number of fruits remaining on the -th tree. Now, we use the sequence to represent the numbers of fruits remaining in the trees.
- On Day , we have .
- On the morning of Day , each tree bears new fruits, and we have .
- On the morning of Day , each tree bears new fruits, and we have .
- On the night of Day , Takahashi performs the -st harvesting. fruits are collected, and we have .
- On the morning of Day , each tree bears new fruits, and we have .
- On the night of Day , Takahashi performs the -nd harvesting. fruits are collected, and we have .
- On the morning of Day , each tree bears new fruits, and we have .
- On the morning of Day , each tree bears new fruits, and we have .
- On the night of Day , Takahashi performs the -rd harvesting. fruits are collected, and we have .
Sample Input 2
711741968710511029 1
82803157126515475 516874290286751784 588060532191410838
Sample Output 2
603657470
Be sure to print the numbers modulo .