QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#442570#8750. 连向未来MindevelopedAC ✓2ms3960kbC++141.4kb2024-06-15 12:49:202024-06-15 12:49:21

Judging History

This is the latest submission verdict.

  • [2024-06-15 12:49:21]
  • Judged
  • Verdict: AC
  • Time: 2ms
  • Memory: 3960kb
  • [2024-06-15 12:49:20]
  • Submitted

answer

#include <cstdio>
#include <iostream>
using namespace std;
const int N=1000003,mod=998244353;
struct Matrix{
	int m,n,a[8][8];
};
int n,m,f[N];
int pow(int a,long long b)
{
	int ans=1;
	while(b>0)
	{
		if(b&1) ans=(long long)ans*a%mod;
		a=(long long)a*a%mod; b>>=1;
	}
	return ans;
}
Matrix operator*(Matrix a,Matrix b)
{
	Matrix ans={};
	ans.m=a.m,ans.n=b.n;
	for(int i=0;i<a.m;i++)
		for(int j=0;j<b.n;j++)
			for(int k=0;k<a.n;k++)
				ans.a[i][j]=(ans.a[i][j]+(long long)a.a[i][k]*b.a[k][j]%mod)%mod;
	return ans;
}
void get_pow(Matrix& ans,Matrix a,long long b)
{
	while(b>0)
	{
		if(b&1) ans=ans*a;
		a=a*a; b>>=1;
	}
}
int main()
{
//	freopen("future.in","r",stdin);
//	freopen("future.out","w",stdout);
	int i,j,t,g0,g1,g2;
	for(scanf("%d",&t);t>0;t--)
	{
		scanf("%d%d",&n,&m);
		if((long long)n*m%3!=0)
		{
			printf("0\n");
			continue;
		}
		if(n==1)
		{
			printf("%d\n",pow(2,m/3));
			continue;
		}
		if(n==2)
		{
			Matrix mf={1,2,{{1,8}}};
			Matrix mul={2,2,{{4,32},{1,10}}};
			get_pow(mf,mul,m/3);
			printf("%d\n",mf.a[0][0]);
			continue;
		}
		Matrix mf={1,6,{1,0,0,0,0,0}},mul={6,6,{
			{2,1,0,0,0,0},
			{8,0,1,0,0,1},
			{8,0,0,0,0,0},
			{4,0,0,0,1,0},
			{8,0,0,0,0,1},
			{16,0,0,2,0,0}
		}};
		get_pow(mf,mul,m);
		printf("%d\n",mf.a[0][0]);
	}
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3960kb

input:

55
2 8031210
3 10210712
2 9120723
2 3150628
1 11011026
1 4190502
3 6090201
1 1170519
3 7221226
2 8010207
2 9190808
3 2101102
3 1010205
2 4170816
1 7131023
1 3040925
3 6130723
1 9210219
3 5040212
1 12121223
2 970305
2 3010502
1 1230417
1 4030425
3 6290131
2 5300907
3 12161016
2 881222515
3 2050920
1 ...

output:

806076119
588810720
38317172
0
113529008
882202894
269215950
101196497
705279206
121073849
0
927341027
94730664
516331515
0
0
252086963
683189835
581003019
0
250544636
0
491842958
433831403
149074611
232125280
147111173
0
417818859
0
0
733235574
152856587
592682304
567987185
263535646
97414810
58768...

result:

ok 55 lines

Test #2:

score: 0
Accepted
time: 2ms
memory: 3960kb

input:

100
3 939524095
2 939524095
3 536870911
3 805306367
3 939524094
3 805306366
3 536870910
3 939524093
3 805306365
3 536870909
3 939524091
3 805306363
3 536870907
3 939524087
3 805306359
3 536870903
3 939524079
3 805306351
3 536870895
3 939524063
3 805306335
3 536870879
3 939524031
3 805306303
3 536870...

output:

921004048
0
5428424
728490820
815984617
950522272
510950101
250494384
806535406
687502234
429662844
425931469
591639952
611688166
401487763
338349103
763369074
461622989
294247847
497390993
914122849
879503521
310294156
882539630
973226787
329010477
762931986
674501617
228908595
405400760
207710171
...

result:

ok 100 lines