#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int mx = 1e8;
void solve(){
int n,m;
cin>>n>>m;
if(max(n,m)%min(n,m)==0){
cout<<max(n,m)-1<<endl;
if(n>m){
for(int i = 1;i<n;i++) cout<<1<<" ";
cout<<endl;
}
else{
for(int i = 1;i<m;i++) cout<<-1<<" ";
cout<<endl;
}
}
else if(min(n,m)==2){
cout<<max(n,m)<<endl;
if(n>m){
for(int i = 1;i<=n;i++) {
if(i%2==0) cout<<mx<<" ";
else cout<<-mx+1<<" ";
}
}
else{
for(int i = 1;i<=m;i++) {
if(i%2==0) cout<<-mx<<" ";
else cout<<mx-1<<" ";
}
}
}
else{
if(n-m==1){
cout<<n<<endl;
int sum = 4*(n-2);
cout<<1-sum<<" ";
for(int i = 2;i<n;i++){
cout<<4<<" ";
}
cout<<1-sum<<endl;
}
else if(m-n==1){
cout<<m<<endl;
int sum = 4*(m-2);
cout<<sum-1<<" ";
for(int i = 2;i<m;i++){
cout<<-4<<" ";
}
cout<<sum-1<<endl;
}
else if(n-m==2){
vector<int>xx;
for(int i = 0;i<n || i%m;i++){
if(i%m==0) xx.push_back(-(m-1)*100+1);
else xx.push_back(100);
}
cout<<xx.size()<<endl;
for(int &i:xx) cout<<i<<" ";
cout<<endl;
}
else{
vector<int>xx;
for(int i = 0;i<m || i%n;i++){
if(i%n==0) xx.push_back((n-1)*100-1);
else xx.push_back(-100);
}
cout<<xx.size()<<endl;
for(int &i:xx) cout<<i<<" ";
cout<<endl;
}
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(nullptr);
int t;cin>>t;while(t--)
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |