QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#814558 | #9870. Items | light_ink_dots# | RE | 0ms | 0kb | C++23 | 1.9kb | 2024-12-14 18:19:57 | 2024-12-14 18:19:58 |
answer
#include<bits/stdc++.h>
using namespace std;
const int maxk=20,maxn=1<<maxk,mod=998244353,G=3,invG=(mod+1)/3;
typedef vector<int>poly;
int T,n,lim;
long long m;
int btf[maxn],w[maxk+1][maxn][2];
int ksm(int a,int b){
int res=1;
while(b){
if(b&1)
res=1ll*res*a%mod;
a=1ll*a*a%mod,b>>=1;
}
return res;
}
void init(){
for(int len=2,i=1;i<=maxk;len<<=1,i++){
int o0=ksm(G,(mod-1)/len),o1=ksm(invG,(mod-1)/len);
w[i][0][0]=w[i][0][1]=1;
for(int j=1;j<len;j++)
w[i][j][0]=1ll*w[i][j-1][0]*o0%mod,w[i][j][1]=1ll*w[i][j-1][1]*o1%mod;
}
}
int getlen(int n){
int r=0;
while((1<<r)<n)
r++;
for(int i=0;i<(1<<r);i++)
btf[i]=(btf[i>>1]>>1)|((i&1)<<(r-1));
return (1<<r);
}
inline int inc(int x){
return x>=mod? x-mod:x;
}
void NTT(poly &x,int lim,int opt){
x.resize(lim);
for(int i=0;i<lim;i++)
if(i<btf[i])
swap(x[i],x[btf[i]]);
for(int p=1,l=2;l<=lim;p++,l<<=1)
for(int i=0;i<lim;i+=l)
for(int j=0;j<(l>>1);j++){
int a=x[i+j],b=1ll*x[i+j+(l>>1)]*w[p][j][opt]%mod;
x[i+j]=inc(a+b),x[i+j+(l>>1)]=inc(a-b+mod);
}
if(opt==1){
int v=ksm(lim,mod-2);
for(int i=0;i<lim;i++)
x[i]=1ll*x[i]*v%mod;
}
}
poly operator *(poly a,poly b){
int deg=a.size()+b.size()-1,lim=getlen(deg);
poly res(lim);
NTT(a,lim,0),NTT(b,lim,0);
for(int i=0;i<lim;i++)
res[i]=1ll*a[i]*b[i]%mod;
NTT(res,lim,1),res.resize(deg);
return res;
}
poly mul(poly a,poly b){
poly res=a*b;
poly c(n+n+1);
for(int i=0;i<=n+n;i++)
c[i]=res[n+i]==0? 0:1;
return c;
}
int main(){
init();
scanf("%d",&T);
while(T--){
scanf("%d%lld",&n,&m);
int off=m/n;
poly a(n+n+1);
for(int i=1,x;i<=n;i++)
x=i,a[n+(x-off)]=1;
poly res(n+n+1);
res[n]=1;
int b=n;
while(b){
if(b&1)
res=mul(res,a);
a=mul(a,a),b>>=1;
}
if(res[n+m-1ll*n*off])
puts("Yes");
else puts("No");
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
4 5 25 0 0 0 0 5 5 11 4 4 4 5 5 5 0 1 2 3 4 5 5 25 0 1 2 3 4