Loading

P5591 小猪佩奇学数学

P5591 小猪佩奇学数学

\[\sum_{i=0}^{n}\binom{n}{i}p^i\lfloor\dfrac{i}{k}\rfloor\\ =\sum_{i=0}^{n}\binom{n}{i}p^i\dfrac{i-i\%k}{k}\\ =\dfrac{1}{k}\sum_{i=0}^{n}\binom{n}{i}p^i(i-i\%k)\\ =\dfrac{1}{k}\sum_{i=0}^{n}\binom{n}{i}p^ii-\dfrac{1}{k}\sum_{j=0}^{k-1}j\sum_{i=0}^{n}[i\bmod k=j]\binom{n}{i}p^i \]

\(\dfrac{1}{k}\) 暂且略去。

先看前面,看着很小清新。

\[\sum_{i=0}^{n}\binom{n}{i}p^ii\\ =n\sum_{i=0}^{n}\dfrac{i}{n}\binom{n}{i}p^i\\ =n\sum_{i=0}^{n}\binom{n-1}{i-1}p^i\\ =np\sum_{i=0}^{n-1}\binom{n-1}{i}p^i\\ =np(p+1)^{n-1} \]

再看后面

\[\sum_{j=0}^{k-1}j\sum_{i=0}^{n}[i\bmod k=j]\binom{n}{i}p^i\\ =\dfrac{1}{k}\sum_{j=0}^{k-1}j\sum_{i=0}^{n}\sum_{t=0}^{k-1}\omega_{k}^{t(i-j)}\binom{n}{i}p^i\\ =\dfrac{1}{k}\sum_{t=0}^{k-1}\sum_{j=0}^{k-1}j\omega_{k}^{-tj}\sum_{i=0}^{n}\binom{n}{i}p^i\omega_{k}^{ti}\\ =\dfrac{1}{k}\sum_{t=0}^{k-1}\sum_{j=0}^{k-1}j\omega_{k}^{-tj}(p\omega_{k}^{t}+1)^n\\ =\dfrac{1}{k}\sum_{t=0}^{k-1}(p\omega_{k}^{t}+1)^n\sum_{j=0}^{k-1}j\omega_{k}^{-tj}\\ \]

后面那个 \(\omega\) 是个等差乘等比的形式,习惯性单独拉出来推。

\[S=\sum_{j=0}^{k-1}j(\omega_{k}^{-t})^j\\ \omega_{k}^{-t}S=\sum_{j=1}^{k}(j-1)(\omega_{k}^{-t})^j\\ (1-\omega_{k}^{-t})S=\sum_{j=0}^{k-1}(\omega_{k}^{-t})^j-(k-1)\omega_{k}^{-tk}-1\\ =[k|t]k-(k-1)-1=-k\\ S=\dfrac{k}{\omega_{k}^{-t}-1} \]

哼哼,啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊,一个细节调死人了。这个并不完全是等比数列,开头有 \(0\) ,我大E了,没有闪,被偷袭了。这个就是第三步 \(-1\) 的原因。

还要特判 \(t=0\)

#define mod 998244353
inline int qpow(int n,int k){int res=1;for(;k;k>>=1,n=1ll*n*n%mod)if(k&1)res=1ll*n*res%mod;return res;}
int n,p,k,w[1<<20],ans;
signed main(){
	n=read(),p=read(),k=read();
	w[0]=1,w[1]=qpow(3,(mod-1)/k);
	for(int i=2;i<k;++i)w[i]=1ll*w[i-1]*w[1]%mod;
	ans=1ll*n*p%mod*qpow(p+1,n-1)%mod;
	int res=0;
	for(int i=0;i<k;++i){
		int x=qpow(1ll*p*w[i]%mod+1,n),y=0;
		if(i)y=1ll*k*qpow(w[k-i]-1,mod-2)%mod;
		else y=1ll*k*(k-1)/2%mod;
		res=(res+1ll*x*y%mod)%mod;
	}
	res=1ll*res*qpow(k,mod-2)%mod,ans=(ans+mod-res)%mod;
	ans=1ll*ans*qpow(k,mod-2)%mod;
	cout<<ans<<'\n';
}

posted @ 2021-03-14 16:18  zzctommy  阅读(99)  评论(0编辑  收藏  举报