ZSUM - Just Add It
For two given integers n and k find (Zn+Zn-1-2Zn-2)mod 10000007 , where Zn=Sn+Pn and Sn=1k+2k+3k+…..+nk and Pn=11+22+33+……+nn.
There are several test cases [ ≤10000 ].In each case two space separated positive integers n and k are given.
For last test case n and k are given as 0 0 ,which is not to be processed.
1<n<200000000 , 0<k<1000000.
For each case print the asked value in separate line.
Input: 10 3
|Added by:||Manohar Singh|
|Cluster:||Cube (Intel Pentium G860 3GHz)|
|Languages:||All except: SCM chicken|
thanks @ deadbrain
for those who don't know how to solve the problem efficiently, read Modular exponentiation wiki article first... Lot to learn from this question.