#P5430. [SNOI2017] 礼物 加强版

[SNOI2017] 礼物 加强版

Description

The hospitable little monkey invites friends from the forest to dinner. His friends are numbered from 11 to nn. Each friend who arrives brings him some gifts: big bananas. The first friend brings him 11 big banana. After that, when each friend arrives, they will bring the total number of gifts brought by all previous friends, plus their index raised to the kk-th power.

So, if k=2k=2, the number of gifts brought by the first few friends is:

1,5,15,37,83,1,5,15,37,83,\ldots

If k=3k=3, the number of gifts brought by the first few friends is:

1,9,37,111,1,9,37,111,\ldots

Now, the little monkey is curious about how many gifts he will receive from the nn-th friend, so he asks you for help.

Given n,kn,k, output the number of gifts brought by the nn-th friend mod 109+7\bmod \ 10^9+7.

Input Format

The first line contains two integers n,kn,k.

Output Format

Output one integer, representing the number of gifts brought by the nn-th friend mod 109+7\bmod \ 10^9+7.

4 2
37
2333333 2
514898185
1234567890000 3
891659731
1000000013 10
616417347

Hint

10%\text{10}\% of the testdata: n106n \le 10^6.

Another 10%\text{10}\% of the testdata: k3k \le 3.

The first 40%\text{40}\% of the testdata: n1018,k10n \le 10^{18}, k \le 10.

The first 60%\text{60}\% of the testdata: n1018,k1000n \le 10^{18}, k \le 1000.

The first 70%\text{70}\% of the testdata: k1000k \le 1000.

The first 90%\text{90}\% of the testdata: k106k \le 10^6.

100%\text{100}\% of the testdata: n10100000,k2×107n\le 10^{100000},k \le 2\times10^7.

The time limit for the last test point is 2s2s, and for the others it is 1s1s.


NaCly_Fish: The original testdata for this problem was incorrect and has now been fixed.

Translated by ChatGPT 5