题目传送门:https://www.luogu.org/problemnew/show/P4948
题目大意:令(A_n=n^k imes q^n),求(sumlimits_{i=1}^nA_i)
其实很久以前数学课学了数列就开始想这题了……
但最近才会解法……
我们令(S_k(n)=sumlimits_{i=1}^ni^k imes q^i),对其扰动可得
[egin{align}S_k(n)&=sumlimits_{i=1}^n(i+1)^k imes q^{i+1}-(n+1)^k imes q^{n+1}+q
onumber\&=sumlimits_{i=1}^nsumlimits_{j=0}^kinom{k}{j}i^j imes q^{i+1}-(n+1)^k imes q^{n+1}+q
onumber\&=qsumlimits_{j=0}^kinom{k}{j}S_j(n)-(n+1)^k imes q^{n+1}+q
onumberend{align}
]
所以我们就得到了(S_k(n))的递推式
[S_k(n)=dfrac{(n+1)^k imes q^{n+1}-sumlimits_{j=0}^{k-1}inom{k}{j}S_j(n)-q}{q-1}
]
但是这仅限于(q>1)的情况,那么(q=1)的情况呢,那就是幂和的形式,具体方法可以看这篇博客
/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline char gc(){
static char buf[1000000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
template<typename T>inline T frd(T x){
int f=1; char ch=gc();
for (;ch<'0'||ch>'9';ch=gc()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=gc()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
template<typename T>inline T read(T x){
int f=1; char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
return x*f;
}
inline void print(int x){
if (x<0) putchar('-'),x=-x;
if (x>9) print(x/10);
putchar(x%10+'0');
}
const int N=2e3,p=1e9+7;
int fac[N+10],inv[N+10],T[N+10];
void prepare(){
fac[0]=inv[0]=inv[1]=1;
for (int i=1;i<=N;i++) fac[i]=1ll*i*fac[i-1]%p;
for (int i=2;i<=N;i++) inv[i]=1ll*(p-p/i)*inv[p%i]%p;
for (int i=1;i<=N;i++) inv[i]=1ll*inv[i-1]*inv[i]%p;
}
int C(int n,int m){return 1ll*fac[n]*inv[m]%p*inv[n-m]%p;}
int mlt(ll a,ll b){
int res=1; a%=p; b%=(p-1);
for (;b;b>>=1,a=1ll*a*a%p) if (b&1) res=1ll*res*a%p;
return res;
}
int main(){
prepare();
ll n=read(0ll); int a=read(0),k=read(0);
if (a==1){
T[0]=n%p;
for (int i=1;i<=k;i++){
int res=0;
for (int j=0;j<i;j++) res=(1ll*C(i+1,j)*T[j]+res)%p;
T[i]=1ll*(mlt(n+1,i+1)-res-1)*mlt(i+1,p-2)%p;
}
printf("%d
",(T[k]+p)%p);
}else{
T[0]=1ll*(a-mlt(a,n+1))*mlt(1-a,p-2)%p;
for (int i=1;i<=k;i++){
int res=0;
for (int j=0;j<i;j++) res=(1ll*C(i,j)*T[j]+res)%p;
res=1ll*res*a%p;
T[i]=1ll*(1ll*mlt(n+1,i)*mlt(a,n+1)-a-res)%p*mlt(a-1,p-2)%p;
}
printf("%d
",(T[k]+p)%p);
}
return 0;
}