[LOJ 6485] LJJ 学二项式定理

题意

$\Large \left[ \sum_{i=0}^n \left( {n\choose i} \cdot s^{i} \cdot a_{i\bmod 4} \right) \right] \bmod 998244353$

$$T\le 10^5$$ 组测试数据, $$n\le 10^{18};s,a_i\le 10^9$$.

题解

$\sum_{k=0}^3\sum_{i\bmod 4=k} {n\choose i}a_ks^i$

$$i\bmod 4=k$$ 等价于 $$4\mid i-k$$. 于是我们有:

$\sum_{k=0}^3\sum_{4\mid i-k} {n\choose i}a_ks^i$

$\sum_{k=0}^3\sum_{i}[4\mid i] {n\choose i+k}a_ks^{i+k}$

$\sum_{j=0}^{n-1}(\omega_n^k)^j=0$

$\frac 1 n\sum_{j=0}^{n-1}(\omega_n^k)^j=\frac 1 n\sum_{j=0}^{n-1}\omega_n^{kj}=[k\mid n]$

\begin{aligned} &\sum_{k=0}^3\sum_{i}\left (\frac 1 4\sum_{r=0}^3\omega_4^{ir}\right) {n\choose i+k}a_ks^{i+k}\\ =&\frac 1 4\sum_{k=0}^3\sum_{r=0}^3a_k\sum_{i}{n\choose i+k}s^{i+k}\omega_4^{ir} \\ \end{aligned}

\begin{aligned} &\frac 1 4\sum_{k=0}^3\sum_{r=0}^3a_k\sum_{i}{n\choose i+k}s^{i+k}\omega_4^{(i+k)r}\omega_4^{-kr} \\ =&\frac 1 4\sum_{k=0}^3\sum_{r=0}^3a_k\omega_4^{-kr} \sum_{i}{n\choose i+k}s^{i+k}\omega_4^{(i+k)r}\\ =&\frac 1 4\sum_{k=0}^3\sum_{r=0}^3a_k\omega_4^{-kr} \sum_{i}{n\choose i+k}(s\omega_4^r)^{i+k} \\ =&\frac 1 4\sum_{k=0}^3\sum_{r=0}^3a_k\omega_4^{-kr} (s\omega_4^r+1)^n \end{aligned}

参考代码

#include <bits/stdc++.h>

const int I=911660635;
const int NI=86583718;
const int MOD=998244353;
const int PHI=998244352;
const int INV4=748683265;
typedef long long intEx;

int Pow(int,int,int);

int main(){
int T;
scanf("%d",&T);
while(T--){
intEx n;
int s;
scanf("%lld%d",&n,&s);
int ans=0;
for(int i=0;i<4;i++){
int a;
scanf("%d",&a);
for(int j=0;j<4;j++)
(ans+=1ll*a*Pow(NI,i*j,MOD)%MOD*Pow((1ll*Pow(I,j,MOD)*s+1)%MOD,n%PHI,MOD)%MOD)%=MOD;
}
ans=1ll*ans*INV4%MOD;
printf("%d\n",ans);
}
return 0;
}

inline int Pow(int a,int n,int p){
int ans=1;
while(n>0){
if(n&1)
ans=1ll*a*ans%p;
a=1ll*a*a%p;
n>>=1;
}
return ans;
}

posted @ 2019-06-12 19:25  rvalue  阅读(454)  评论(0编辑  收藏  举报