Ha!! Another easy problem for you!! Or is it not that easy?
Given the integers a, b, M, x,
Plase print (ax+(a+1)x+(a+2)x+...+bx) mod M
First line contains a number T, denoting the number of testcases.
Each testcase consists of the four numbers a, b, x, M in a line.
T <= 500
1 <= a <= b <= 2147483647
0 <= x <= 250
1 <= M <= 1000000010, M is always prime.
For each testcase, output the result of the summation in a line.
3 3 5 2 107 53 57 3 97 1 2 1 2
50 4 1
Migrated from old NTUJ.
kelvin
No. | Testdata Range | Score |
---|