QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#266010 | #7688. Alea Iacta Est | fishfishfriedfish# | RE | 0ms | 0kb | C++14 | 1.9kb | 2023-11-26 00:51:38 | 2023-11-26 00:51:38 |
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<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: 0
Runtime Error
input:
3 2 8 1 9 2 9