QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#266008#7688. Alea Iacta Estfishfishfriedfish#WA 0ms3600kbC++142.0kb2023-11-26 00:43:062023-11-26 00:43:07

Judging History

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

  • [2023-11-26 00:43:07]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3600kb
  • [2023-11-26 00:43:06]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define rep2(i,j,k) for(int i=j;i>=k;i--)
using namespace std;
template<typename T> void read(T &num){
	char c=getchar();T f=1;num=0;
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){num=(num<<3)+(num<<1)+(c^48);c=getchar();}
	num*=f;
}
template<typename T> void qwq(T x){
	if(x>9)qwq(x/10);
	putchar(x%10+'0');
}
template<typename T> void write(T x){
	if(x<0){x=-x;putchar('-');}
	qwq(x);putchar('\n');
}
bool prime(int x){
	if(x==1)return 1;
	if(x<2)return 0;
	for(int i=2;i*i<=x;i++){
		if(x%i==0)return 0;
	}
	return 1;
}
int gcd(int n,int m){
	return (!m)?n:gcd(m,n%m);	
}
vector<int>a,b;
void solve(){
	int n,m;read(n);read(m);
	if(n!=m){
		if(prime(n)&&prime(m)){
			write(0);
			write(0);
			return;	
		}
		long long N=n*m;
		long long tx=0;long long ty=0;
		for(int i=2;1ll*i*i<=N;i++){
			if(N%i)continue;
			tx=i;ty=N/i;
		}
		int n1=gcd(n,(int)tx);int n2=n/n1;
		int m1=tx/n1;int m2=m/m1;
		a.clear();b.clear();
		rep(i,0,n1-1){
			rep(j,0,m1-1){
				a.push_back(i*n2+j*m2+1);
			}
		}
		rep(i,0,n2-1){
			rep(j,0,m2-1){
				b.push_back(i+j+1);
			}
		}
		qwq(n1*m1);
		rep(i,0,(int)a.size()-1){putchar(' ');qwq(a[i]);}
		putchar('\n');
		qwq(n2*m2);
		rep(i,0,(int)b.size()-1){putchar(' ');qwq(b[i]);}
		putchar('\n');
	}else{
		if(prime(n)){
			write(0);
			write(0);	
		}else{
			int tx=0;
			for(int i=2;i*i<=n;i++){
				if(n%i==0){
					tx=i;
					break;
				}
			}
			int n1=tx;int n2=n/tx;
			int m1=n/tx;int m2=tx;
			a.clear();b.clear();
			rep(i,0,n1-1){
				rep(j,0,m1-1){
					a.push_back(i*n2+j*m2+1);
				}
			}
			rep(i,0,n2-1){
				rep(j,0,m2-1){
					b.push_back(i+j+1);
				}
			}
			qwq(n1*m1);
			rep(i,0,(int)a.size()-1){putchar(' ');qwq(a[i]);}
			putchar('\n');
			qwq(n2*m2);
			rep(i,0,(int)b.size()-1){putchar(' ');qwq(b[i]);}
			putchar('\n');
		}
	}
	return;
}
int main(){
	int t;read(t);
	while(t--)solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

3
2 8
1 9
2 9

output:

4 1 5 2 6
4 1 2 3 4
3 1 4 7
3 1 2 3
3 1 4 7
6 1 2 3 2 3 4

result:

ok Correct. (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3600kb

input:

1
40013 40013

output:

0
0

result:

wrong answer Integer parameter [name=n1] equals to 0, violates the range [1, 120039] (test case 1)