eolymp
bolt
Try our new interface for solving problems
Problems

Just Add It

Just Add It

For two given integers $n$ and $k$ find $$ (Z_n + Z_{n-1} - 2 \cdot Z_{n-2})~mod~10000007, $$ where $$ Z_n = S_n + P_n, $$ $$ S_n = 1^k + 2^k + 3^k + ... + n^k, $$ $$ P_n = 1^1 + 2^2 + 3^3 + ... + n^n $$ \InputFile There are several test cases. Each case is a separate line that contains two positive integers $n$ and $k~(1 < n < 2 \cdot 10^8, 0 < k < 10^6)$. The last line contains two zeros and should not be processed. \OutputFile For each test case print the required value in a separate line.
Time limit 1 second
Memory limit 128 MiB
Input example #1
10 3
9 31
83 17
5 2
0 0
Output example #1
4835897
2118762
2285275
3694