#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){
if(max(n,m)==8) cout<<n<<m<<endl;
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{
cout<<max(n,m)<<endl;
if(n-m==1){
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){
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){
for(int i = 0;i<n;i++){
if(i%m==0) cout<<-(m-1)*100+1<<" ";
else cout<<100<<" ";
}
cout<<endl;
}
else{
for(int i = 0;i<m;i++){
if(i%n==0) cout<<(n-1)*100-1<<" ";
else cout<<-100<<" ";
}
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... |