链接
题解
前置技能:单位根反演
令 M = 2 m M=2^m M=2m,对于一个确定的余数 r r r,答案推导如下
∑ i = 0 n [ 2 m ] [ x i ] ( 1 + 2 x ) n = ∑ i = 0 n 1 M ∑ j = 0 M − 1 ω M ( i − r ) j [ x i ] ( 1 + 2 x ) n = 1 M ∑ j = 0 M − 1 ω M − r j ∑ i = 0 n [ x i ] ( 1 + 2 x ) n ( ω M j ) i = 1 M ∑ j = 0 M − 1 ω M − r j ( 1 + 2 W m j ) n \sum_{i=0}^n [2^m] [x^i](1+2x)^n \\ = \sum_{i=0}^n \frac{1}{M} \sum_{j=0}^{M-1} \omega_M^{(i-r)j} [x^i] (1+2x)^n\\ = \frac{1}{M} \sum_{j=0}^{M-1} \omega_{M}^{-rj} \sum_{i=0}^{n} [x^i] (1+2x)^n (\omega_M^j)^i \\ = \frac{1}{M} \sum_{j=0}^{M-1} \omega_{M}^{-rj} (1+2W_m^j)^n i=0∑n[2m][xi](1+2x)n=i=0∑nM1j=0∑M−1ωM(i−r)j[xi](1+2x)n=M1j=0∑M−1ωM−rji=0∑n[xi](1+2x)n(ωMj)i=M1j=0∑M−1ωM−rj(1+2Wmj)n
令 p = 2222303 p=2222303 p=2222303,最终答案推导如下:
a n s = ∑ r = 0 M − 1 p r 1 M ∑ j = 0 M − 1 ω M − r j ( 1 + 2 W m j ) n = 1 M ∑ j = 0 M − 1 ( 1 + 2 W m j ) n ∑ r = 0 M − 1 ( p ω M − j ) r ans = \sum_{r=0}^{M-1} p^r \frac{1}{M} \sum_{j=0}^{M-1} \omega_{M}^{-rj} (1+2W_m^j)^n \\ = \frac{1}{M} \sum_{j=0}^{M-1} (1+2W_m^j)^n \sum_{r=0}^{M-1} (p\omega_{M}^{-j})^r ans=r=0∑M−1prM1j=0∑M−1ωM−rj(1+2Wmj)n=M1j=0∑M−1(1+2Wmj)nr=0∑M−1(pωM−j)r
代码
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define eps 1e-8
#define maxn 1000010
#define maxe 1000010
#define cl(x) memset(x,0,sizeof(x))
#define rep(i,a,b) for(i=a;i<=b;i++)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define de(x) cerr<<#x<<" = "<<x<<endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
ll read(ll x=0)
{
ll c, f(1);
for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
for(;isdigit(c);c=getchar())x=x*10+c-0x30;
return f*x;
}
#define mod 998244353ll
ll n, m, M;
ll fastpow(ll a, ll b)
{
ll t(a%mod), ans(1);
b=(b%(mod-1)+(mod-1))%(mod-1);
for(;b;t=t*t%mod,b>>=1)if(b&1)(ans*=t)%=mod;
return ans;
}
int main()
{
ll j, p=2222303, wm, _wm, ans=0, wmj, _wmj;
n=read(), m=read();
M=1ll<<m;
wm=fastpow(3,mod-1>>m), _wm=fastpow(wm,mod-2);
wmj=_wmj=1;
rep(j,0,M-1)
{
ll a=fastpow(1+2*wmj,n), q=p*_wmj%mod, tmp;
if((q+mod)%mod==1)tmp=M;
else tmp = ( 1 - fastpow(q,M) ) * fastpow(1-q,mod-2) %mod;
(ans+=a*tmp)%=mod;
(wmj*=wm)%=mod, (_wmj*=_wm)%=mod;
}
ans=ans*fastpow(M,mod-2)%mod;
printf("%lld",(ans+mod)%mod);
return 0;
}