数学题

也许更好的阅读体验

D e s c r i p t i o n \mathcal{Description} Description

n , b , k n,b,k n,b,k,求
<mstyle displaystyle="true" scriptlevel="0"> <munderover> i = 1 n </munderover> ( <mstyle displaystyle="false" scriptlevel="0"> i </mstyle> <mstyle displaystyle="false" scriptlevel="0"> k </mstyle> ) b i </mstyle> \begin{aligned}\sum_{i=1}^n\begin{pmatrix}i\\k \end{pmatrix}b^i\end{aligned} i=1n(ik)bi

答案对 998244353 998244353 998244353取模

1 k 500000 , 1 n 1 0 18 , 2 b 998244353 1\leq k\leq 500000,1\leq n\leq 10^{18},2\leq b\leq 998244353 1k500000,1n1018,2b998244353

S o l u t i o n \mathcal{Solution} Solution


<mstyle displaystyle="true" scriptlevel="0"> f k = <munderover> i = 1 n </munderover> ( <mstyle displaystyle="false" scriptlevel="0"> i </mstyle> <mstyle displaystyle="false" scriptlevel="0"> k </mstyle> ) b i </mstyle> \begin{aligned}f_{k}=\sum ^{n}_{i=1}\begin{pmatrix} i \\ k \end{pmatrix}b^{i}\end{aligned} fk=i=1n(ik)bi

则有
<mstyle displaystyle="true" scriptlevel="0"> f k 1 = <munderover> i = 1 n </munderover> ( <mstyle displaystyle="false" scriptlevel="0"> i </mstyle> <mstyle displaystyle="false" scriptlevel="0"> k 1 </mstyle> ) b i </mstyle> \begin{aligned}f_{k-1}=\sum ^{n}_{i=1}\begin{pmatrix} i \\ k-1 \end{pmatrix}b^{i}\end{aligned} fk1=i=1n(ik1)bi

<mstyle displaystyle="true" scriptlevel="0"> b f k = <munderover> i = 2 n + 1 </munderover> ( <mstyle displaystyle="false" scriptlevel="0"> i 1 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> k </mstyle> ) b i </mstyle> \begin{aligned}bf_{k}=\sum ^{n+1}_{i=2}\begin{pmatrix} i-1 \\ k \end{pmatrix}b^{i}\end{aligned} bfk=i=2n+1(i1k)bi

<mstyle displaystyle="true" scriptlevel="0"> b f k 1 = <munderover> i = 2 n + 1 </munderover> ( <mstyle displaystyle="false" scriptlevel="0"> i 1 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> k 1 </mstyle> ) b i </mstyle> \begin{aligned}bf_{k-1}=\sum ^{n+1}_{i=2}\begin{pmatrix} i-1 \\ k-1 \end{pmatrix}b^{i}\end{aligned} bfk1=i=2n+1(i1k1)bi

<mstyle displaystyle="true" scriptlevel="0"> b f k + b f k 1 = <munderover> i = 2 n + 1 </munderover> ( ( <mstyle displaystyle="false" scriptlevel="0"> i 1 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> k </mstyle> ) + ( <mstyle displaystyle="false" scriptlevel="0"> i 1 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> k 1 </mstyle> ) ) b i = <munderover> i = 2 n + 1 </munderover> ( <mstyle displaystyle="false" scriptlevel="0"> i </mstyle> <mstyle displaystyle="false" scriptlevel="0"> k </mstyle> ) b i = f k + ( <mstyle displaystyle="false" scriptlevel="0"> n + 1 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> k </mstyle> ) b n + 1 ( <mstyle displaystyle="false" scriptlevel="0"> 1 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> k </mstyle> ) b </mstyle> \begin{aligned}bf_{k}+bf_{k-1}=\sum ^{n+1}_{i=2}\left(\begin{pmatrix} i-1 \\ k \end{pmatrix}+\begin{pmatrix} i-1 \\ k-1 \end{pmatrix}\right)b^{i}=\sum ^{n+1}_{i=2}\begin{pmatrix} i \\ k \end{pmatrix}b^{i}=f_k+\begin{pmatrix}n+1\\ k\end{pmatrix}b^{n+1}-\begin{pmatrix}1\\k\end{pmatrix}b\end{aligned} bfk+bfk1=i=2n+1((i1k)+(i1k1))bi=i=2n+1(ik)bi=fk+(n+1k)bn+1(1k)b

移项得

( b 1 ) f k = ( <mstyle displaystyle="false" scriptlevel="0"> n + 1 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> k </mstyle> ) b n + 1 ( <mstyle displaystyle="false" scriptlevel="0"> 1 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> k </mstyle> ) b b f k 1 \left(b-1\right)f_k=\begin{pmatrix}n+1\\k\end{pmatrix}b^{n+1}-\begin{pmatrix}1\\k\end{pmatrix}b-bf_{k-1} (b1)fk=(n+1k)bn+1(1k)bbfk1

f k = <mstyle displaystyle="true" scriptlevel="0"> ( <mstyle displaystyle="false" scriptlevel="0"> n + 1 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> k </mstyle> ) b n + 1 ( <mstyle displaystyle="false" scriptlevel="0"> 1 </mstyle> <mstyle displaystyle="false" scriptlevel="0"> k </mstyle> ) b b f k 1 b 1 </mstyle> f_k=\dfrac{\begin{pmatrix}n+1\\k\end{pmatrix}b^{n+1}-\begin{pmatrix}1\\k\end{pmatrix}b-bf_{k-1}}{b-1} fk=b1(n+1k)bn+1(1k)bbfk1

k = 0 k=0 k=0时,要求的就是一个等比数列,我们用等比数列求和公式直接算就可以了

f 0 = <mstyle displaystyle="true" scriptlevel="0"> b n + 1 b b 1 </mstyle> f_0=\dfrac{b^{n+1}-b}{b-1} f0=b1bn+1b

总复杂度 O ( k ) O(k) O(k)

C o d e \mathcal{Code} Code

/******************************* Author:Morning_Glory LANG:C++ Created Time:2019年09月17日 星期二 10时54分50秒 *******************************/
#include <cstdio>
#include <fstream>
#define ll long long
using namespace std;
const int mod = 998244353;
const int maxn = 500005;
ll n,b,k,ans;
ll invb,mi,C;
ll inv[maxn];
//{{{ksm
ll ksm (ll a,ll b)
{
	a%=mod;
	ll s=1;
	for (;b;b>>=1,a=a*a%mod)
		if (b&1)	s=s*a%mod;
	return s;
}
//}}}
int main()
{
	scanf("%lld%lld%lld",&n,&b,&k);
	C=(n+1)%mod,inv[1]=1,invb=ksm(b-1,mod-2);
	for (int i=2;i<=k;++i)	inv[i]=(-mod/i*inv[mod%i]%mod+mod)%mod;
	ans=(ksm(b,n+1)-b+mod)%mod*invb%mod;
	mi=ksm(b,n+1);
	if (n<k){	printf("0\n");return 0;}
	if (n==k){	printf("%lld\n",ksm(b,n));return 0;}
	for (int i=1;i<=k;++i){
		ll t=0;
		if (i<=1)	t=b;
		ans=((C*mi%mod-t-b*ans%mod)%mod+mod)%mod*invb%mod;
		C=(n-i+1)%mod*C%mod*inv[i+1]%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

如有哪里讲得不是很明白或是有错误,欢迎指正
如您喜欢的话不妨点个赞收藏一下吧

全部评论

相关推荐

2024-11-28 21:33
广东工业大学 Java
点赞 评论 收藏
分享
2024-12-07 17:42
佛山大学 销售工程师
亲切的长颈鹿又在摸鱼:找销售啊,算法机器人不是你这个学历能干的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务