题面
题解
orzljz
我们分块,设\(s=\sqrt{p}+1\),那么\(x^a\)可以拆成\((x^s)^{a/s}\)和\(x^{a\bmod s}\),\(O(s)\)预处理,\(O(1)\)计算就可以了
//minamoto#include#define R register#define inline __attribute__((always_inline))#define fp(i,a,b) for(R int i=(a),I=(b)+1;i I;--i)#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)using namespace std;char buf[1<<21],*p1=buf,*p2=buf;inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}int read(){ R int 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]=' ';}const int N=50005,P=998244352;inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}inline int dec(R int x,R int y){return x-y<0?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 int y){ R int res=1; for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0; return res;}int bin[N],bs[N],n,x,s,a;int main(){// freopen("testdata.in","r",stdin); x=read(),n=read(),s=sqrt(P)+1; bin[0]=1;fp(i,1,s)bin[i]=mul(bin[i-1],x); bs[0]=1;fp(i,1,s)bs[i]=mul(bs[i-1],bin[s]); while(n--)a=read(),print(mul(bs[a/s],bin[a%s])); return Ot(),0;}