标签:int get sdi git long bsp turn swa ret
推导可得
ans=(n+1)(n+2)(n+3)(n+4)/24
于是乎打了一发py
mdTLE
然后迫不得已写了一发ntt
#include<cstdio> #include<algorithm> #include<iostream> const int mod = 998244353,g=3; const int maxn = 1001000; typedef long long ll; inline int pow(int a,int b,int ans=1){ for(;b;b>>=1,a=ll(a)*a%mod) if(b&1)ans=ll(ans)*a%mod; return ans; } inline int inv(int x){return pow(x,mod-2);} int wn[maxn],rev[maxn],lim; inline void init(int len){ *wn=lim=1; while(lim<len)lim<<=1; for(int i=1;i<lim;++i)rev[i]=rev[i>>1]>>1|(i%2*lim/2); } inline int reduce(int x){return x+(x>>31&mod);} inline void fst(int*a,int type){ for(int i=1;i<lim;++i)if(rev[i]>i)std::swap(a[rev[i]],a[i]); for(int mid=1;mid<lim;mid<<=1){ const int W=pow(g,mod/mid/2); for(int k=1;k<mid;++k)wn[k]=ll(wn[k-1])*W%mod; for(int j=0;j<lim;j+=mid+mid){ for(int*A=a+j,*B=A+mid,*w=wn;w!=wn+mid;++A,++B,++w){ const int x=*A,y=ll(*B)**w%mod; *A=reduce(x+y-mod),*B=reduce(x-y); } } } if(!type){ for(int i=0,lm=inv(lim);i<lim;++i)a[i]=ll(a[i])*lm%mod; std::reverse(a+1,a+lim); } } int a[maxn],b[maxn],c[maxn],d[maxn]; char buf[maxn]; int n; inline void get(int * a){ for(int i=0;i+1<maxn;++i) a[i+1]+=a[i]/10,a[i]%=10; } inline void div24(int*a){ for(int i=maxn-1,res=0;~i;--i){ res *= 10,res += a[i]; a[i] = res / 24,res %= 24; } } int main(){ fread(buf,1,sizeof buf,stdin); for(n=0;isdigit(buf[n]);++n); std::reverse_copy(buf,buf+n,a); for(int i=0;i<n;++i) b[i]=c[i]=d[i]=a[i]-=48; a[0]+=1,b[0]+=2,c[0]+=3,d[0]+=4; init(n<<1); fst(a,1),fst(b,1),fst(c,1),fst(d,1); for(int i=0;i<lim;++i)a[i]=ll(a[i])*c[i]%mod,b[i]=ll(b[i])*d[i]%mod; fst(a,0),fst(b,0); get(a),get(b); init(n<<2); fst(a,1),fst(b,1); for(int i=0;i<lim;++i)a[i]=ll(a[i])*b[i]%mod; fst(a,0),get(a),div24(a); for(n=maxn-1;!a[n];--n); for(int i=n;~i;--i)putchar(a[i]+48); }
标签:int get sdi git long bsp turn swa ret
原文地址:https://www.cnblogs.com/skip1978/p/10346470.html