Under construction

Still being built. Things may change

Power of Power Partition Function

Time limit2sMemory limit512 MB

Summary
Given n up to 1e18, m up to 1e18, and k up to 10, compute the sum of the k-th convolution power of the m-ary partition function up to n, modulo 1e9+7.
Level

Hard9 of 10

Topics
Number theory, Divide and conquer, Dynamic programming, Math
Solved
No attempts yet

Problem

Let mm be a fixed integer with m≥2m \ge 2. For a positive integer nn, bm(n)b_m(n) is the number of ways to write nn as a sum of powers of mm with non-negative exponents. Repetitions are allowed, and the order of the summands does not matter. We also set bm(0)=1b_m(0) = 1, since the empty sum is one way.

For example, the first 10 terms of {b2(n)}\{b_2(n)\} are {1,1,2,2,4,4,6,6,10,10}\{1, 1, 2, 2, 4, 4, 6, 6, 10, 10\}, and the first 10 terms of {b3(n)}\{b_3(n)\} are {1,1,1,2,2,2,3,3,3,5}\{1, 1, 1, 2, 2, 2, 3, 3, 3, 5\}.

Let cmk(n)c_m^k(n) be the kk-th convolution power of bm(n)b_m(n), defined as follows.

cmk(n)={bm(n),k=1∑i=0nbm(i)⋅cmk−1(n−i),k≥2c_m^k(n)=\begin{cases} b_m(n), & k = 1 \\ \sum_{i=0}^{n} b_m(i) \cdot c_m^{k-1}(n-i), & k \ge 2 \end{cases}

Given nn, mm, and kk, Bobo wants to find the value of

f(n)=(∑i=0ncmk(i)) mod (109+7).f(n) = \left( \sum_{i=0}^{n} c_m^k(i) \right) \bmod (10^9 + 7).

Input

The first line contains three integers nn, mm, and kk (0≤n≤10180 \le n \le 10^{18}, 2≤m≤10182 \le m \le 10^{18}, 1≤k≤101 \le k \le 10).

Output

Print the value of f(n)f(n).

Examples3

  1. Example 1

    Input
    0 2 1
    
    Expected output
    1
    
  2. Example 2

    Input
    10 2 3
    
    Expected output
    2700
    
  3. Example 3

    Input
    100 2 10
    
    Expected output
    490796617