#include<bits/stdc++.h>
bool Mbg;
using namespace std;
#define vec vector
#define pb push_back
#define eb emplace_back
#define SZ(vec) (int)((vec).size())
#define all(vec) (vec).begin(),(vec).end()
#define pii pair<int,int>
#define x first
#define y second
#define mp make_pair
#define exc(expr) if(expr)continue;
#define stop(expr) if(expr)break;
#define ret(expr) if(expr)return;
#define deb(var) std::cerr<<#var<<'='<<(var)<<"; "
#define debl(var) std::cerr<<#var<<'='<<(var)<<";\n"
#define debs(...) std::cerr << "(" << #__VA_ARGS__ << ")=(", deb_out(__VA_ARGS__)
void deb_out() { cerr<<");\n"; }
template <typename H>void deb_out(H h) { std::cerr << h << ");\n"; }
template <typename H, typename...T>void deb_out(H h, T... t){ std::cerr << h << ","; deb_out(t...); }
template<typename T>std::ostream& operator <<(std::ostream& os,const vector<T>& arr){
if(arr.empty())return os;
os<<arr[0];
for(int i=1;i<arr.size();i++)os<<' '<<arr[i];
return os;
}
#define ins insert
#define era erase
#define lb lower_bound
#define ub upper_bound
#define int long long
#define inf (long long)(1.1e18)
template<typename T>bool Min(T &x,const T &y){return x>y?x=y,1:0;}
template<typename T>bool Max(T &x,const T &y){return x<y?x=y,1:0;}
const int mod=1e9+7;
void Add(int &x,const int &y){x=x+y<mod?x+y:x+y-mod;}
void Dec(int &x,const int &y){x=x>=y?x-y:x-y+mod;}
int fpm(int x,int y){
int ans=1;for(;y;y>>=1,x=1ll*x*x%mod)if(y&1)ans=1ll*x*ans%mod;return ans;
}
int n,m,k;
int dp[1000010],S[1000010],iv[1000010];
int p[1000010],S1[1000010],S2[1000010];
void work(){
cin>>n>>k>>m;
iv[1]=1;
for(int i=2;i<=1e6;i++){
iv[i]=(mod-mod/i)*iv[mod%i]%mod;
}
dp[0]=1;
S[0]=1;
for(int i=1;i<=m;i++){
dp[i]=(S[i-1]-(i-k-1>=0?S[i-k-1]:0)+mod)*iv[k]%mod;
S[i]=(S[i-1]+dp[i])%mod;
}
p[0]=1;
S1[0]=1;
S2[0]=min(m-1,k);
for(int x=1;x<=m;x++){
// p[x]:某个人得分第一次不小于x时,游戏还没结束的概率
p[x]=S1[x-1]*(1-x+mod)+S2[x-1];
if(x-k-1>=0){
(p[x]+=S1[x-k-1]*(x-1)+mod-S2[x-k-1])%=mod;
}
p[x]%=mod;
(p[x]*=iv[k])%=mod;
S1[x]=(S1[x-1]+dp[x])%mod;
S2[x]=(S2[x-1]+dp[x]*min(m-1,x+k))%mod;
}
int ans=0;
for(int x=0;x<m;x++){
int a=p[x+1]*fpm(p[x],mod-2)%mod;
if(a==1){
(ans+=a*n%mod*fpm(p[x],n-1)%mod*dp[x])%=mod;
}else{
(ans+=(fpm(a,n)-1+mod)*fpm(a-1+mod,mod-2)%mod*fpm(p[x],n-1)%mod*dp[x])%=mod;
}
}
cout<<ans<<'\n';
}
bool Med;
signed main(){
ios::sync_with_stdio(0),
cin.tie(0),cout.tie(0);
int T=1;while(T--)work();
// cerr<<"Time: "<<clock()<<" ms;\n";
// cerr<<"Memory: "<<abs(&Med-&Mbg)/1024.0/1024.0<<" MiB.\n";
}
/*
- CONTINUE, NON-STOPPING, FOR THE FAITH
- START TYPING IF YOU DON'T KNOW WHAT TO DO
- STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
*/
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | #include<bits/stdc++.h> bool Mbg; using namespace std; #define vec vector #define pb push_back #define eb emplace_back #define SZ(vec) (int)((vec).size()) #define all(vec) (vec).begin(),(vec).end() #define pii pair<int,int> #define x first #define y second #define mp make_pair #define exc(expr) if(expr)continue; #define stop(expr) if(expr)break; #define ret(expr) if(expr)return; #define deb(var) std::cerr<<#var<<'='<<(var)<<"; " #define debl(var) std::cerr<<#var<<'='<<(var)<<";\n" #define debs(...) std::cerr << "(" << #__VA_ARGS__ << ")=(", deb_out(__VA_ARGS__) void deb_out() { cerr<<");\n"; } template <typename H>void deb_out(H h) { std::cerr << h << ");\n"; } template <typename H, typename...T>void deb_out(H h, T... t){ std::cerr << h << ","; deb_out(t...); } template<typename T>std::ostream& operator <<(std::ostream& os,const vector<T>& arr){ if(arr.empty())return os; os<<arr[0]; for(int i=1;i<arr.size();i++)os<<' '<<arr[i]; return os; } #define ins insert #define era erase #define lb lower_bound #define ub upper_bound #define int long long #define inf (long long)(1.1e18) template<typename T>bool Min(T &x,const T &y){return x>y?x=y,1:0;} template<typename T>bool Max(T &x,const T &y){return x<y?x=y,1:0;} const int mod=1e9+7; void Add(int &x,const int &y){x=x+y<mod?x+y:x+y-mod;} void Dec(int &x,const int &y){x=x>=y?x-y:x-y+mod;} int fpm(int x,int y){ int ans=1;for(;y;y>>=1,x=1ll*x*x%mod)if(y&1)ans=1ll*x*ans%mod;return ans; } int n,m,k; int dp[1000010],S[1000010],iv[1000010]; int p[1000010],S1[1000010],S2[1000010]; void work(){ cin>>n>>k>>m; iv[1]=1; for(int i=2;i<=1e6;i++){ iv[i]=(mod-mod/i)*iv[mod%i]%mod; } dp[0]=1; S[0]=1; for(int i=1;i<=m;i++){ dp[i]=(S[i-1]-(i-k-1>=0?S[i-k-1]:0)+mod)*iv[k]%mod; S[i]=(S[i-1]+dp[i])%mod; } p[0]=1; S1[0]=1; S2[0]=min(m-1,k); for(int x=1;x<=m;x++){ // p[x]:某个人得分第一次不小于x时,游戏还没结束的概率 p[x]=S1[x-1]*(1-x+mod)+S2[x-1]; if(x-k-1>=0){ (p[x]+=S1[x-k-1]*(x-1)+mod-S2[x-k-1])%=mod; } p[x]%=mod; (p[x]*=iv[k])%=mod; S1[x]=(S1[x-1]+dp[x])%mod; S2[x]=(S2[x-1]+dp[x]*min(m-1,x+k))%mod; } int ans=0; for(int x=0;x<m;x++){ int a=p[x+1]*fpm(p[x],mod-2)%mod; if(a==1){ (ans+=a*n%mod*fpm(p[x],n-1)%mod*dp[x])%=mod; }else{ (ans+=(fpm(a,n)-1+mod)*fpm(a-1+mod,mod-2)%mod*fpm(p[x],n-1)%mod*dp[x])%=mod; } } cout<<ans<<'\n'; } bool Med; signed main(){ ios::sync_with_stdio(0), cin.tie(0),cout.tie(0); int T=1;while(T--)work(); // cerr<<"Time: "<<clock()<<" ms;\n"; // cerr<<"Memory: "<<abs(&Med-&Mbg)/1024.0/1024.0<<" MiB.\n"; } /* - CONTINUE, NON-STOPPING, FOR THE FAITH - START TYPING IF YOU DON'T KNOW WHAT TO DO - STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING */ |
English