ZSUM - Just Add It

no tags 

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.

Input

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.

Constraints

1 < n < 200000000
0 < k < 1000000

Output

For each case print the asked value in separate line.

Example

Input:
10 3
9 31
83 17
5 2
0 0

Output:
4835897
2118762
2285275
3694

hide comments
sea_26: 2019-07-29 20:07:02

AC in one go with 0.01 Sec

shreyash1999: 2019-07-01 14:05:26

i m getting all answers correct except 10 3 it is comming negative value in have taken long long also

mubasshir00: 2019-05-22 21:48:34

Just Use Binary Exponentiation and Sum of N number formula :-p then GET AC and thanks me

yashraj_: 2019-01-07 15:57:48

Something to learn for beginners

masterchef2209: 2018-12-22 13:48:31

#ACin1GO

tanardi gunawan: 2018-11-02 10:32:30

aci no nego

yuhta: 2018-10-16 05:34:38

Be careful it is NOT 1e9+7, it's 1e7+7

pallav17: 2018-06-24 08:55:03

im coding in c how can i reduce its runtime....right now its taking 2.3sec ...???

nadstratosfer: 2018-06-01 19:56:01

Pure Python works just fine here.

imkiller: 2018-06-01 14:47:13

Python is giving TLE ..but cpp solved!
Using FASTIO 0.02

Last edit: 2018-06-01 14:47:45

Added by:Manohar Singh
Date:2011-09-04
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Manohar Singh