1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include<bits/stdc++.h>
using namespace std;
typedef uint32_t u32;
typedef uint64_t u64;
constexpr int N=1e6+5,P=1e9+7;
inline u32 dec(const u32 x){return min(x,x-P);}
inline u32 power(u32 x,u32 y=P-2){
    u32 ans=1;
    while(y)y&1?ans=(u64)ans*x%P:0,x=(u64)x*x%P,y>>=1;
    return ans;
}

#define gc getchar_unlocked
#define pc putchar_unlocked
inline int read(){
    int x=0; char c=gc();
    while(!isdigit(c))c=gc();
    while(isdigit(c))x=x*10+c-'0',c=gc();
    return x;
}
void write(const int x){
    if(x>9)write(x/10);
    pc(x%10+'0');
}

int n,k,m;
u32 invk,f[N],sf[N];

int main(){
    n=read(),k=read(),m=read();
    f[0]=sf[0]=1,invk=power(k);
    for(int i=1;i<=m;i++){
        f[i]=(u64)dec(sf[i-1]-(i-k-1>=0?sf[i-k-1]:0)+P)*invk%P;
        sf[i]=dec(sf[i-1]+f[i]);
    }
    u32 g=1,ans=0;
    for(int i=0;i<m;i++){
        if(i&&i-1+k>=m)g=dec(g-(u64)f[i-1]*(i+k-m)%P*invk%P+P);
        u32 p=(u64)max(i+k-m+1,0)*invk%P;
        if(p)ans=(ans+(u64)(power(g,n)-power(dec(g-(u64)f[i]*p%P+P),n)+P)*power(p))%P;
        else ans=(ans+(u64)n*f[i]%P*power(g,n-1))%P;
    }
    write(ans),pc('\n');
    return 0;
}