QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#266005 | #7688. Alea Iacta Est | fishfishfriedfish# | WA | 0ms | 3612kb | C++14 | 1.9kb | 2023-11-26 00:37:36 | 2023-11-26 00:37:37 |
Judging History
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<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){
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)||n==1){
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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: 3612kb
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)