QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#324167#8017. 计算lgvc0 106ms13796kbC++149.2kb2024-02-10 16:33:252024-02-10 16:33:25

Judging History

你现在查看的是最新测评结果

  • [2024-02-10 16:33:25]
  • 评测
  • 测评结果:0
  • 用时:106ms
  • 内存:13796kb
  • [2024-02-10 16:33:25]
  • 提交

answer

#include <bits/stdc++.h>
static char buf[1000000],*paa=buf,*pd=buf;
static char buf2[1000000],*pp=buf2;
#define getchar() paa==pd&&(pd=(paa=buf)+fread(buf,1,1000000,stdin),paa==pd)?EOF:*paa++
inline void pc(char ch){
	if(pp-buf2==1000000) fwrite(buf2,1,1000000,stdout),pp=buf2;
	*pp++=ch;
}
inline void pcc(){
	fwrite(buf2,1,pp-buf2,stdout);
	pp=buf2;
}
inline int read(void) {
	int w=1;
	register int x(0);register char c(getchar());
	while(c<'0'||c>'9') {if(c=='-') w=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return w*x;
}
void write(int x) {
	if(x<0) pc('-'),x=-x;
	static int sta[20];
	int top=0;
	do {
		sta[top++]=x%10,x/=10;
	} while(x);
	while(top) pc(sta[--top]+48);
}
void we(int x) {
	write(x);
	pc('\n');
}
#define pai 3.141592653589793238462643383279502884197169399375105820
#define md(x) ((x)>=MOD?(x)-MOD:(x))
int rev[4000009],p[1000009],iv[1000009];
const int g=3,MOD=998244353,MAX=1000005;
struct complex{
    double x,y;
    complex(double x=0,double y=0):x(x),y(y){}
    inline complex operator+(complex b) {
		return complex(x+b.x,y+b.y);
    }
    inline complex operator-(complex b) {
        return complex(x-b.x,y-b.y);
    }
    inline complex operator*(complex b) {
        complex res;
		res.x=x*b.x-y*b.y;
		res.y=x*b.y+y*b.x;
		return res;
    }
};
inline int pw(int a,int b) {
	int as=1;
	while(b) {
		if(b&1) as=1ll*as*a%MOD;
		a=1ll*a*a%MOD;
		b>>=1;
	}
	return as;
}
inline int ni(int a) {
	return pw(a,MOD-2);
}
void binom(void) {
	p[0]=1;
	for(int i=1;i<=MAX;i++) p[i]=1ll*p[i-1]*i%MOD;
	iv[MAX]=ni(p[MAX]);
	for(int i=MAX-1;i>=0;i--) iv[i]=1ll*iv[i+1]*(i+1)%MOD;
}
struct poly{
	std::vector<int> f;
	inline int sz(void) {
		return f.size()-1;
	}
	inline void input(int sz) {
		for(int i=0;i<=sz;i++) {
			f.push_back(read());
		}
	}
	inline void output() {
		for(int i=0;i<f.size();i++) write(f[i]),pc(' ');
		pcc();
	}
	inline void FFT(std::vector<complex>& a,int t,int lim) {
		for(int i=1;i<=lim;i++) if(i<rev[i]) std::swap(a[i],a[rev[i]]);
		complex rt,w,x,y;
		for(int mid=1;mid<lim;mid<<=1) {
			int r=mid<<1;
			rt=complex(cos(pai/mid),t*sin(pai/mid));
			for(int j=0;j<lim;j+=r) {
				w=complex(1,0);
				for(int k=0;k<mid;k++) {
					x=a[j|k];
					y=w*a[j|k|mid];
					a[j|k]=x+y;
					a[j|k|mid]=x-y;
					w=w*rt;
				}
			}
		}
		if(t==1) return;
		for(int i=0;i<=lim;i++) a[i].x/=lim,a[i].y/=lim; 
	}
	inline void NTT(std::vector<int>& a,int t,int lim,int g) {
		for(int i=1;i<=lim;i++) if(i<rev[i]) std::swap(a[i],a[rev[i]]);
		int rt,w,x,y;
		for(int mid=1;mid<lim;mid<<=1) {
			int r=mid<<1;
			rt=pw(g,(MOD-1)/r);
			if(t==-1) rt=ni(rt);
			for(int j=0;j<lim;j+=r) {
				w=1;
				for(int k=0;k<mid;k++) {
					x=a[j|k];
					y=1ll*w*a[j|k|mid]%MOD;
					a[j|k]=((x+y>=MOD)?(x+y-MOD):(x+y));
					a[j|k|mid]=((x-y<0)?(x-y+MOD):(x-y));
					w=1ll*w*rt%MOD;
				}
			}
		}
		if(t==1) return;
		int qq=ni(lim);
		for(int i=0;i<=lim;i++) a[i]=1ll*a[i]*qq%MOD;
	}
/*	inline poly operator*(poly a) {
		int n=std::max(f.size()-1,a.f.size()-1),lim=1,x=-1;
		while(lim<=(n<<1)) {
			lim<<=1;
			x++;
		}
		for(int i=1;i<=lim;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<x);
		std::vector<complex> tp;tp.resize(lim+1);
		for(int i=0;i<f.size();i++) tp[i].x=f[i];
		for(int i=0;i<a.f.size();i++) tp[i].y=a.f[i];	
		FFT(tp,1,lim);
		for(int i=0;i<=lim;i++) tp[i]=tp[i]*tp[i];
		FFT(tp,-1,lim);
		poly c;c.f.resize(f.size()-1+a.f.size());
		for(int i=0;i<f.size()-1+a.f.size();i++) {
			c.f[i]=tp[i].y/2+0.5;
			c.f[i]%=MOD;
		}
		return c;
	}*/
	inline poly operator+(poly a) {
		int n=std::max(f.size()-1,a.f.size()-1);
		a.f.resize(n+1);
		for(int i=0;i<f.size();i++) {
			a.f[i]=(a.f[i]+f[i])>=MOD?(a.f[i]+f[i])-MOD:(a.f[i]+f[i]); 
		}
		return a;
	}
	inline poly operator+(int x) {
		poly a;a.f=f;a.f[0]=(a.f[0]+x>=MOD)?(a.f[0]+x-MOD):(a.f[0]+x); 
		return a;
	}
	inline poly operator-(poly a) {
		int n=std::max(f.size()-1,a.f.size()-1);
		a.f.resize(n+1);
		for(int i=0;i<f.size();i++) {
			a.f[i]=(f[i]-a.f[i])<0?(f[i]-a.f[i])+MOD:(f[i]-a.f[i]); 
		}
		for(int i=f.size();i<=n;i++) {
			a.f[i]=(a.f[i]==0?0:(MOD-a.f[i]));
		}
		return a;
	}
	inline poly operator-(int x) {
		poly a;a.f=f;a.f[0]=(a.f[0]-x<0)?(a.f[0]-x+MOD):(a.f[0]-x); 
		return a;
	}
	inline poly operator*(int a) {
		poly tmp;tmp.f=f;
		for(int i=0;i<f.size();i++) tmp.f[i]=1ll*tmp.f[i]*a%MOD;
		return tmp;
	} 
	inline poly operator/(int a) {
		poly tmp;tmp.f=f;a=ni(a);
		for(int i=0;i<f.size();i++) tmp.f[i]=1ll*tmp.f[i]*a%MOD;
		return tmp;
	} 
	inline poly operator*(poly a) {
		if(a.f.size()<=16||f.size()<=16) {
			poly tp;
			tp.f.resize(f.size()-1+a.f.size());
			for(int i=0;i<f.size();i++) {
				for(int j=0;j<a.f.size();j++) {
					int as=1ll*f[i]*a.f[j]%MOD;
					tp.f[i+j]=(tp.f[i+j]+as)>=MOD?(tp.f[i+j]+as)-MOD:(tp.f[i+j]+as);
				}
			}
			return tp;
		}
		int n=std::max(f.size()-1,a.f.size()-1),lim=1,x=-1,ss=f.size()-1+a.f.size();
		while(lim<=(n<<1)) {
			lim<<=1;
			x++;
		}
		for(int i=1;i<=lim;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<x);
		poly tmp;tmp.f=f;
		tmp.f.resize(lim+1);
		a.f.resize(lim+1);
		NTT(tmp.f,1,lim,g);
		NTT(a.f,1,lim,g);
		for(int i=0;i<=lim;i++) tmp.f[i]=1ll*tmp.f[i]*a.f[i]%MOD;
		NTT(tmp.f,-1,lim,g);
		tmp.f.resize(ss);
		return tmp;		
	} 
	inline poly dao(void) {
		poly tmp;
		for(int i=1;i<f.size();i++) {
			tmp.f.push_back(1ll*f[i]*i%MOD);
		}
		return tmp;
	} 
	inline poly ivdao(void) {
		poly tmp;
		tmp.f.push_back(0);
		for(int i=0;i<f.size();i++) {
			tmp.f.push_back(1ll*f[i]*iv[i+1]%MOD*p[i]%MOD);
		}
		return tmp;
	} 
	inline poly sqr(void) {
		if(f.size()<=16) {
			poly tp;
			tp.f.resize(f.size()-1+f.size());
			for(int i=0;i<f.size();i++) {
				for(int j=0;j<f.size();j++) {
					int as=1ll*f[i]*f[j]%MOD;
					tp.f[i+j]=(tp.f[i+j]+as)>=MOD?(tp.f[i+j]+as)-MOD:(tp.f[i+j]+as);
				}
			}
			return tp;
		}
		int n=f.size()-1,lim=1,x=-1,ss=f.size()-1+f.size();
		while(lim<=(n<<1)) {
			lim<<=1;
			x++;
		}
		for(int i=1;i<=lim;i++) rev[i]=(rev[i>>1]>>1)|((i&1)<<x);
		poly tmp;tmp.f=f;
		tmp.f.resize(lim+1);
		NTT(tmp.f,1,lim,g);
		for(int i=0;i<=lim;i++) tmp.f[i]=1ll*tmp.f[i]*tmp.f[i]%MOD;
		NTT(tmp.f,-1,lim,g);
		tmp.f.resize(ss);
		return tmp;		
	} 
	inline poly inv(void) {
		poly tmp,tmp3;tmp3.f.push_back(f[0]);
		tmp.f.push_back(ni(f[0]));
		int s=f.size(),qq=0,a[30];
		a[++qq]=s;
		while(s>1) a[++qq]=(s+1)/2,s=a[qq];
		for(int i=qq-1;i>=1;i--) {
			for(int j=a[i+1];j<a[i];j++) tmp3.f.push_back(f[j]);
			tmp=tmp*2-tmp3*tmp.sqr();
			tmp.f.resize(a[i]);
		}
		return tmp;
	}
	inline poly ln(void) {
		poly qq=(this->dao()*this->inv()).ivdao();
		qq.f.resize(f.size());
		return qq;
	}
	inline poly exp(void) {
		poly tmp,tmp3;tmp3.f.push_back(f[0]);
		tmp.f.push_back(1);
		int s=f.size(),a[30],qq=0;
		a[++qq]=s;
		while(s>1) a[++qq]=(s+1)/2,s=a[qq];
		for(int i=qq-1;i>=1;i--) {
			for(int j=a[i+1];j<a[i];j++) tmp3.f.push_back(f[j]);
			poly tmp4=tmp;
			tmp.f.resize(a[i]);
			tmp=tmp4*(tmp3-tmp.ln()+1);
			tmp.f.resize(a[i]);
		}
		return tmp;
	}
	inline poly sqrt(void) {
		poly tmp,tmp3;tmp3.f.push_back(f[0]);
		tmp.f.push_back(1);
		int s=f.size(),a[30],qq=0;
		a[++qq]=s;
		while(s>1) a[++qq]=(s+1)/2,s=a[qq];
		for(int i=qq-1;i>=1;i--) {
			for(int j=a[i+1];j<a[i];j++) tmp3.f.push_back(f[j]);
			poly tmp5=tmp3+tmp.sqr();
			tmp.f.resize(a[i]);
			tmp=tmp5*(tmp*2).inv();
			tmp.f.resize(a[i]);
		}
		return tmp;		
	}
	inline poly ksm(int x) {
		if(x<64) {
			poly a,b;
			a.f=f;
			b.f.push_back(1); 
			while(x) {
				if(x&1) b=b*a;
				b.f.resize(f.size());
				x>>=1;
				a=a.sqr();
				a.f.resize(f.size());
			}
			return b;
		}
		poly tmp;tmp.f=f;
		tmp=tmp.ln();
		tmp=tmp*x;
		tmp=tmp.exp();
		return tmp;
	}
};
poly sv(int l,int r,int m) {
	if(l==r) {
		if(l==m) {
			poly tp;tp.f.push_back(2);
			return tp;
		}
		poly tp;tp.f.resize(l+1);
		tp.f[l]=tp.f[0]=1;
		return tp;
	}
	poly tp=sv(l,(l+r)>>1,m)*sv((l+r+2)>>1,r,m);
	if(tp.f.size()>m) {
		for(int i=m;i<tp.f.size();i++) {
			tp.f[i-m]=md(tp.f[i-m]+tp.f[i]);
		}
		tp.f.resize(m);
	}
	return tp;
}
inline int sv(long long a,long long m) {
	a/=m;
	poly tp;
	tp.f.push_back(2);
	for(int i=1;i<m;i++) tp.f.push_back(0);
	for(int i=1;i<m;i++) {
		poly as=tp;
		for(int j=0;j<m;j++) {
			as.f[(i+j>=m)?(i+j-m):(i+j)]=md(as.f[(i+j>=m)?(i+j-m):(i+j)]+tp.f[j]);
		}
		tp=as;
	}
	poly as;
	as.f.push_back(1);
	printf("ok\n");
	while(a) {
		printf("%lld\n",a);
		if(a&1) {
			as=as*tp;
			if(as.f.size()>m) {
				for(int i=m;i<as.f.size();i++) {
					as.f[i-m]=md(as.f[i-m]+as.f[i]);
				}
				as.f.resize(m);
			}
		}
		tp=tp.sqr();
		if(tp.f.size()>m) {
			for(int i=m;i<tp.f.size();i++) {
				tp.f[i-m]=md(tp.f[i-m]+tp.f[i]);
			}
			tp.f.resize(m);
		}
		a>>=1;
	}
	return as.f[0];
}
signed main(void) {
	int T,m,a,b,c,d;
	scanf("%d",&T);
	binom();
	while(T--) {
		scanf("%d %d %d %d %d",&m,&a,&b,&c,&d);
		if(a==0||b==0) a=0;
		else a=std::__gcd(a,b);
		if(c==0||d==0) c=0;
		else c=std::__gcd(c,d);
		long long a1=1,a2=1;
		for(int i=1;i<=a;i++) a1=a1*m;
		for(int i=1;i<=c;i++) a2=a2*m;
		if(a==0) a1=0;
		printf("%d\n",sv(a2-a1,m));
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 7ms
memory: 12192kb

input:

1
2 0 0 1 1

output:

ok
1
2

result:

wrong output format Expected integer, but "ok" found

Test #2:

score: 0
Time Limit Exceeded

input:

10000
9026580 948 269 622 88
9346507 381 242 826 606
9266080 948 589 28 666
8566088 808 523 402 338
9832014 278 123 146 1000
8000150 613 878 146 740
8296526 404 147 608 398
9062880 494 203 336 382
9375271 823 736 54 676
8465119 505 414 874 772
9535971 784 983 426 802
8258325 817 977 172 862
9656017 ...

output:


result:


Test #3:

score: 0
Time Limit Exceeded

input:

10000
9060194 192 71 24 178
8861291 135 338 24 794
8800613 173 760 704 362
9878509 367 418 58 964
8183946 856 951 406 316
8087229 458 105 770 342
8269502 205 147 614 334
8877019 851 143 206 10
9044859 710 949 210 584
8887395 571 856 550 428
8208494 383 628 74 646
9949585 697 450 794 738
9938335 224 ...

output:


result:


Test #4:

score: 0
Time Limit Exceeded

input:

10000
9110615 854 153 494 298
9386442 749 922 386 696
9270958 160 53 630 562
9643022 573 997 226 836
9824638 357 16 34 332
9962202 439 312 40 854
8974913 815 436 710 876
9362731 411 272 998 760
9814831 220 961 962 274
9310979 19 890 782 588
9425378 897 14 212 870
9572172 430 419 334 166
9101141 565 ...

output:


result:


Test #5:

score: 0
Wrong Answer
time: 7ms
memory: 13212kb

input:

4
3 4 5 6 1
2 6 1 8 10
4 1 4 2 2
5 0 10 2 10

output:

ok
1
ok
1
2
ok
3
1
1024
ok
5
2
1
6710912

result:

wrong output format Expected integer, but "ok" found

Test #6:

score: 0
Wrong Answer
time: 11ms
memory: 11968kb

input:

5
18 10 9 4 6
14 7 4 4 6
18 6 5 8 2
12 5 2 4 10
11 5 6 2 6

output:

ok
17
8
4
2
1
8581218
ok
13
6
3
1
487933114
ok
17
8
4
2
1
8581218
ok
11
5
2
1
919504178
ok
10
5
2
1
296665006

result:

wrong output format Expected integer, but "ok" found

Test #7:

score: 0
Wrong Answer
time: 11ms
memory: 12208kb

input:

5
11 9 5 3 3
12 8 9 9 6
10 10 7 3 9
10 5 4 3 6
6 9 6 4 8

output:

ok
120
60
30
15
7
3
1
336307822
ok
143
71
35
17
8
4
2
1
997249957
ok
99
49
24
12
6
3
1
706112470
ok
99
49
24
12
6
3
1
706112470
ok
180
90
45
22
11
5
2
1
856358531

result:

wrong output format Expected integer, but "ok" found

Test #8:

score: 0
Wrong Answer
time: 7ms
memory: 12644kb

input:

5
4 5 6 5 10
12 8 5 9 3
10 4 9 9 3
10 5 6 6 3
6 5 7 4 8

output:

ok
255
127
63
31
15
7
3
1
336848941
ok
143
71
35
17
8
4
2
1
997249957
ok
99
49
24
12
6
3
1
706112470
ok
99
49
24
12
6
3
1
706112470
ok
215
107
53
26
13
6
3
1
811628181

result:

wrong output format Expected integer, but "ok" found

Test #9:

score: 0
Wrong Answer
time: 11ms
memory: 12060kb

input:

5
11 80 29 27 84
11 31 27 87 6
4 46 54 95 80
6 45 62 88 92
12 70 34 3 75

output:

ok
120
60
30
15
7
3
1
336307822
ok
120
60
30
15
7
3
1
336307822
ok
252
126
63
31
15
7
3
1
488237375
ok
215
107
53
26
13
6
3
1
811628181
ok
132
66
33
16
8
4
2
1
306984283

result:

wrong output format Expected integer, but "ok" found

Test #10:

score: 0
Wrong Answer
time: 12ms
memory: 12836kb

input:

5
58 91 37 75 5
62 99 67 10 75
55 51 92 70 85
55 86 16 50 85
29 54 95 36 78

output:

ok
11316495
5658247
2829123
1414561
707280
353640
176820
88410
44205
22102
11051
5525
2762
1381
690
345
172
86
43
21
10
5
2
1
413751362
ok
14776335
7388167
3694083
1847041
923520
461760
230880
115440
57720
28860
14430
7215
3607
1803
901
450
225
112
56
28
14
7
3
1
582959663
ok
9150624
4575312
2287656...

result:

wrong output format Expected integer, but "ok" found

Test #11:

score: 0
Wrong Answer
time: 12ms
memory: 13036kb

input:

5
10 57 94 99 18
19 97 77 63 98
62 44 4 90 35
61 3 54 25 60
62 57 65 95 70

output:

ok
99999999
49999999
24999999
12499999
6249999
3124999
1562499
781249
390624
195312
97656
48828
24414
12207
6103
3051
1525
762
381
190
95
47
23
11
5
2
1
329246322
ok
47045880
23522940
11761470
5880735
2940367
1470183
735091
367545
183772
91886
45943
22971
11485
5742
2871
1435
717
358
179
89
44
22
11...

result:

wrong output format Expected integer, but "ok" found

Test #12:

score: 0
Wrong Answer
time: 11ms
memory: 13096kb

input:

5
5 0 0 9 5
4 0 0 1 5
2 0 0 7 5
3 0 0 3 7
3 0 0 9 5

output:

ok
1
8
ok
1
4
ok
1
2
ok
1
4
ok
1
4

result:

wrong output format Expected integer, but "ok" found

Test #13:

score: 0
Wrong Answer
time: 101ms
memory: 13796kb

input:

5
1931 633 387 65 265
1334 942 887 115 455
1547 511 57 65 920
1815 983 313 575 430
1497 749 773 25 740

output:

ok
13903654866360
6951827433180
3475913716590
1737956858295
868978429147
434489214573
217244607286
108622303643
54311151821
27155575910
13577787955
6788893977
3394446988
1697223494
848611747
424305873
212152936
106076468
53038234
26519117
13259558
6629779
3314889
1657444
828722
414361
207180
103590
...

result:

wrong output format Expected integer, but "ok" found

Test #14:

score: 0
Wrong Answer
time: 105ms
memory: 12436kb

input:

5
1676 347 892 10 545
1552 901 243 595 705
1585 181 32 900 215
1043 147 153 250 195
1343 519 863 610 345

output:

ok
7890346168575
3945173084287
1972586542143
986293271071
493146635535
246573317767
123286658883
61643329441
30821664720
15410832360
7705416180
3852708090
1926354045
963177022
481588511
240794255
120397127
60198563
30099281
15049640
7524820
3762410
1881205
940602
470301
235150
117575
58787
29393
146...

result:

wrong output format Expected integer, but "ok" found

Test #15:

score: 0
Wrong Answer
time: 102ms
memory: 12596kb

input:

5
1507 98 480 995 565
1130 476 464 710 925
1556 518 459 65 445
1153 277 530 485 860
1329 191 777 315 905

output:

ok
5157663558894
2578831779447
1289415889723
644707944861
322353972430
161176986215
80588493107
40294246553
20147123276
10073561638
5036780819
2518390409
1259195204
629597602
314798801
157399400
78699700
39349850
19674925
9837462
4918731
2459365
1229682
614841
307420
153710
76855
38427
19213
9606
48...

result:

wrong output format Expected integer, but "ok" found

Test #16:

score: 0
Wrong Answer
time: 106ms
memory: 12784kb

input:

5
1260 985 161 855 395
1919 286 557 10 155
1439 586 749 915 730
1297 750 832 245 855
1693 134 289 355 200

output:

ok
2520473759999
1260236879999
630118439999
315059219999
157529609999
78764804999
39382402499
19691201249
9845600624
4922800312
2461400156
1230700078
615350039
307675019
153837509
76918754
38459377
19229688
9614844
4807422
2403711
1201855
600927
300463
150231
75115
37557
18778
9389
4694
2347
1173
58...

result:

wrong output format Expected integer, but "ok" found

Test #17:

score: 0
Time Limit Exceeded

input:

5
95803 976 729 633 237
99669 606 7 489 816
80026 339 914 753 933
97238 844 430 666 537
70169 394 204 411 738

output:


result:


Test #18:

score: 0
Time Limit Exceeded

input:

5
86711 965 851 300 273
97658 466 416 633 603
89583 407 591 411 3
84126 987 514 822 837
79996 9 166 807 15

output:


result:


Test #19:

score: 0
Time Limit Exceeded

input:

5
90325 2 48 195 528
83446 123 809 897 60
92466 526 768 441 447
95582 319 251 843 447
95424 374 218 162 597

output:


result:


Test #20:

score: 0
Time Limit Exceeded

input:

5
80746 952 565 615 192
71949 878 950 357 789
99398 301 646 942 699
94853 670 947 141 276
82409 554 873 375 213

output:


result: