loj#6485. LJJ 学二项式定理（单位根反演）

题解

${1\over k}\sum_{i=0}^{k-1}\omega^{in}_k=[k|n]$

\begin{aligned} \sum_{i=1}^n a_i[k|i] &={1\over k}\sum_{i=1}^na_i\sum_{j=0}^{k-1}{\omega_k^{ji}}\\ &={1\over k}\sum_{j=0}^{k-1}\sum_{i=1}^na_i{\omega_k^{ji}}\\ &={1\over k}\sum_{j=0}^{k-1}f(\omega_k^j) \end{aligned}

\begin{aligned} ans &=\sum_{k=0}^3a_k\sum_{j=0}^{n}{n\choose i}S^i[i\equiv k\ \bmod\ 4]\\ &=\sum_{k=0}^3a_k\sum_{j=0}^{n}{n\choose i}S^{n-i}[n-i\equiv k\ \bmod\ 4]\\ &=\sum_{k=0}^3a_{n-k\bmod 4}\sum_{j=0}^{n}{n\choose i}S^{n-i}[i\equiv k\ \bmod\ 4]\\ &={1\over 4}\sum_{k=0}^3a_{n-k\bmod 4}\sum_{j=0}^{3}{f(\omega_4^j)\over \omega_4^{jk}}\\ \end{aligned}

//minamoto
#include<bits/stdc++.h>
#define R register
#define ll long long
#define fp(i,a,b) for(R int i=a,I=b+1;i<I;++i)
#define fd(i,a,b) for(R int i=a,I=b-1;i>I;--i)
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
R ll res,f=1;R char ch;
while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
return res*f;
}
char sr[1<<21],z[20];int C=-1,Z=0;
inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
void print(R int x){
if(C>1<<20)Ot();if(x<0)sr[++C]='-',x=-x;
while(z[++Z]=x%10+48,x/=10);
while(sr[++C]=z[Z],--Z);sr[++C]='\n';
}
const int P=998244353;
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R ll y){
R int res=1;
for(;y;y>>=1,x=mul(x,x))if(y&1)res=mul(res,x);
return res;
}
const int w[4]={1,911660635,998244352,86583718};
const int invw[4]={1,86583718,998244352,911660635};
ll n,now,a[4];int s,res,f[4];
int main(){
//  freopen("testdata.in","r",stdin);
fp(i,0,3)f[i]=ksm((w[i]+s)%P,n);
res=0;
fp(i,0,3){
now=0;fp(j,0,3)now+=f[j];
fp(j,0,3)f[j]=mul(f[j],invw[j]);
}
print(mul(res,748683265));
}
return Ot(),0;
}

• 0
点赞
• 0
评论
• 0
收藏
• 一键三连
• 扫一扫，分享海报

09-24 4055

11-20 37
01-14 33
08-13 112
08-13 56
07-24 34
05-21 33
06-20 42
09-19 5511