QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#266011#7688. Alea Iacta Estfishfishfriedfish#WA 0ms3552kbC++142.0kb2023-11-26 00:53:512023-11-26 00:53:52

Judging History

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

  • [2023-11-26 00:53:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3552kb
  • [2023-11-26 00:53:51]
  • 提交

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(prime(n)&&prime(m)){
		write(0);
		write(0);
		return;	
	}
	if(n!=m){
		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;
		}
		if(tx==min(n,m)&&ty==max(n,m)){
			for(int i=2;1ll*i*i<=N&&i<min(n,m);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{
		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;
}

詳細信息

Test #1:

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

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: 3552kb

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)