[LOJ 6485]LJJ学二项式定理(单位根反演)

也许更好的阅读体验

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

原题链接

T T T组询问,每次给 n , s , a 0 , a 1 , a 2 , a 3 n,s,a_0,a_1,a_2,a_3 n,s,a0,a1,a2,a3
<mstyle displaystyle="true" scriptlevel="0"> ( <munderover> i = 0 n </munderover> ( <mstyle displaystyle="false" scriptlevel="0"> n </mstyle> <mstyle displaystyle="false" scriptlevel="0"> i </mstyle> ) s i a i <mtext>   </mtext> m o d <mtext>   </mtext> 4 ) m o d <mtext>   </mtext> 998244353 </mstyle> \begin{aligned}\left(\sum ^{n}_{i=0}\begin{pmatrix} n \\ i \end{pmatrix}\cdot s^{i}\cdot a_{i\ mod\ 4}\right)mod\ 998244353\end{aligned} (i=0n(ni)siai mod 4)mod 998244353

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

这道题要用单位根反演
<mstyle displaystyle="true" scriptlevel="0"> [ n <mtext>   </mtext> <mtext>   </mtext> k ] = 1 n <munderover> i = 0 n 1 </munderover> w n i k </mstyle> \begin{aligned}\left[ n\ |\ k\right] =\dfrac {1}{n}\sum ^{n-1}_{i=0}w^{ik}_{n}\end{aligned} [n  k]=n1i=0n1wnik

我们先打表,或者查表找出在模 998244353 998244353 998244353下的原根 ω 4 0 \omega_4^0 ω40并处理好 ω 4 1 , ω 4 2 , ω 4 3 \omega_4^1,\omega_4^2,\omega_4^3 ω41,ω42,ω43
考虑对每个 a i a_i ai单独计算其答案
a 0 a_0 a0为例
<mstyle displaystyle="true" scriptlevel="0"> a n s a 0 </mstyle> <mstyle displaystyle="true" scriptlevel="0"> = 1 4 a 0 <munderover> i = 0 n </munderover> [ 4 <mtext>   </mtext> <mtext>   </mtext> i ] ( n i ) s i </mstyle> <mstyle displaystyle="true" scriptlevel="0"> </mstyle> <mstyle displaystyle="true" scriptlevel="0"> = 1 4 a 0 <munderover> i = 0 n </munderover> ( n i ) s i <munderover> j = 0 3 </munderover> ( ω 4 j ) i </mstyle> <mstyle displaystyle="true" scriptlevel="0"> </mstyle> <mstyle displaystyle="true" scriptlevel="0"> = 1 4 a 0 <munderover> j = 0 3 </munderover> <munderover> i = 0 n </munderover> ( n i ) s i ( ω 4 j ) i </mstyle> <mstyle displaystyle="true" scriptlevel="0"> </mstyle> <mstyle displaystyle="true" scriptlevel="0"> = 1 4 a 0 <munderover> j = 0 3 </munderover> ( s ω 4 j + 1 ) n </mstyle> \begin{aligned} ans_{a_0}&amp;=\frac{1}{4}a_0\sum_{i=0}^n [4\ |\ i]{n\choose i}s^i\\ &amp;=\frac{1}{4}a_0\sum_{i=0}^n{n\choose i}s^i\sum_{j=0}^3 (\omega_4^{j})^i\\ &amp;=\frac{1}{4}a_0\sum_{j=0}^3\sum_{i=0}^n {n\choose i}s^i(\omega_4^j)^i\\ &amp;=\frac{1}{4}a_0\sum_{j=0}^3(s\omega_4^j+1)^n \end{aligned} ansa0=41a0i=0n[4  i](in)si=41a0i=0n(in)sij=03(ω4j)i=41a0j=03i=0n(in)si(ω4j)i=41a0j=03(sω4j+1)n

对于其他 a i a_i ai,我们可以将其写成 [ 4 <mtext>   </mtext> <mtext>   </mtext> i + 4 k ] [4\ |\ i+4-k] [4  i+4k]的形式,并提一个 ω x \omega^x ωx出来
下面完整的推一遍

<mstyle displaystyle="true" scriptlevel="0"> a n s </mstyle> <mstyle displaystyle="true" scriptlevel="0"> = <munderover> k = 0 3 </munderover> a k <munderover> i = 0 n </munderover> [ 4 <mtext>   </mtext> <mtext>   </mtext> i + 4 k ] s i ( <mstyle displaystyle="false" scriptlevel="0"> n </mstyle> <mstyle displaystyle="false" scriptlevel="0"> i </mstyle> ) </mstyle> <mstyle displaystyle="true" scriptlevel="0"> </mstyle> <mstyle displaystyle="true" scriptlevel="0"> = <munderover> k = 0 3 </munderover> 1 4 a k <munderover> i = 0 n </munderover> <munderover> j = 0 3 </munderover> ω 4 j ( i + 4 k ) s i ( <mstyle displaystyle="false" scriptlevel="0"> n </mstyle> <mstyle displaystyle="false" scriptlevel="0"> i </mstyle> ) </mstyle> <mstyle displaystyle="true" scriptlevel="0"> </mstyle> <mstyle displaystyle="true" scriptlevel="0"> = <munderover> k = 0 3 </munderover> 1 4 a k <munderover> i = 0 n </munderover> <munderover> j = 0 3 </munderover> ω 4 ( 4 j j k ) ω 4 j i s i ( <mstyle displaystyle="false" scriptlevel="0"> n </mstyle> <mstyle displaystyle="false" scriptlevel="0"> i </mstyle> ) </mstyle> <mstyle displaystyle="true" scriptlevel="0"> </mstyle> <mstyle displaystyle="true" scriptlevel="0"> = <munderover> k = 0 3 </munderover> 1 4 a k <munderover> j = 0 3 </munderover> ω 4 ( 4 j j k ) <munderover> i = 0 n </munderover> ω j i s i ( <mstyle displaystyle="false" scriptlevel="0"> n </mstyle> <mstyle displaystyle="false" scriptlevel="0"> i </mstyle> ) </mstyle> <mstyle displaystyle="true" scriptlevel="0"> </mstyle> <mstyle displaystyle="true" scriptlevel="0"> = <munderover> k = 0 3 </munderover> 1 4 a k <munderover> j = 0 3 </munderover> ω 4 ( 4 j j k ) ( s ω 4 j + 1 ) n </mstyle> \begin{aligned}ans&amp;=\sum ^{3}_{k=0}a_{k}\sum ^{n}_{i=0}\left[ 4\ |\ i+4-k\right] s^{i}\cdot \begin{pmatrix} n \\ i \end{pmatrix}\\ &amp;=\sum ^{3}_{k=0}\dfrac {1}{4}a_{k}\sum ^{n}_{i=0}\sum ^{3}_{j=0}\omega^{j\cdot\left( i+4-k\right) }_{4}\cdot s^{i}\cdot \begin{pmatrix} n \\ i \end{pmatrix}\\ &amp;=\sum ^{3}_{k=0}\dfrac {1}{4}a_{k}\sum ^{n}_{i=0}\sum ^{3}_{j=0}\omega^{\left(4j-jk\right) }_{4}\cdot \omega^{j^i}_4\cdot s^{i}\cdot \begin{pmatrix} n \\ i \end{pmatrix}\\ &amp;=\sum ^{3}_{k=0}\dfrac {1}{4}a_{k}\sum ^{3}_{j=0}\omega^{\left(4j-jk\right) }_{4}\sum ^{n}_{i=0} \omega^{j^i}\cdot s^{i}\cdot \begin{pmatrix} n \\ i \end{pmatrix}\\ &amp;=\sum ^{3}_{k=0}\dfrac {1}{4}a_{k}\sum ^{3}_{j=0}\omega^{\left(4j-jk\right) }_{4}\left(s\cdot \omega^j_4+1\right)^n \\ \end{aligned} ans=k=03aki=0n[4  i+4k]si(ni)=k=0341aki=0nj=03ω4j(i+4k)si(ni)=k=0341aki=0nj=03ω4(4jjk)ω4jisi(ni)=k=0341akj=03ω4(4jjk)i=0nωjisi(ni)=k=0341akj=03ω4(4jjk)(sω4j+1)n
拿出来,再写一遍
<mstyle displaystyle="true" scriptlevel="0"> a n s = <munderover> i = 0 3 </munderover> 1 4 a i <munderover> j = 0 3 </munderover> ω 4 ( 4 j i j ) ( s ω 4 j + 1 ) n </mstyle> \begin{aligned}ans=\sum ^{3}_{i=0}\dfrac {1}{4}a_{i}\sum ^{3}_{j=0}\omega^{\left(4j-ij\right) }_{4}\left(s\cdot \omega^j_4+1\right)^n \\ \end{aligned} ans=i=0341aij=03ω4(4jij)(sω4j+1)n

C o d e \mathcal{Code} Code

#include <cstdio>
#define ll long long
using namespace std;
const int mod = 998244353;
const int w [] = {1,911660635,998244352,86583718};
ll T,n,s,ans,res,inv;
ll a[4];
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",&T);
	inv=ksm(4,mod-2);
	while (T--){
		scanf("%lld%lld%lld%lld%lld%lld",&n,&s,&a[0],&a[1],&a[2],&a[3]);
		ans=0;
		for (int i=0;i<=3;++i){
			res=0;
			for (int j=0;j<=3;++j)
				res=(res+w[(4*j-i*j)%4]*ksm(s*w[j]+1,n)%mod)%mod;
			ans=(ans+a[i]*res%mod)%mod;
		}
		printf("%lld\n",ans*inv%mod);
	}
	return 0;
}

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

全部评论

相关推荐

12-11 14:09
已编辑
中国海洋大学 数值策划
点赞 评论 收藏
分享
头像
11-07 01:12
重庆大学 Java
精致的小松鼠人狠话不多:签哪了哥
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务