#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define ff first
#define ss second
#define ln "\n"
#define mp make_pair
const ll INF = 2e18;
const ll MOD = 1e9+7;
void solve(){
ll n, m; cin >> n >> m;
ll mx = max(m, n), mn = min(m, n);
if (mx%mn==0){
cout << mx-1 << ln;
for (ll i=0; i<mx-1; i++){
cout << (mn==n?-1:1) << " ";
}
cout << ln;
}else{
ll mid = (mx/mn+1)*mn-mx;
vector<ll> res;
if (mn-mid>=mid){
ll lc = (mn-mid+1)/__gcd(mn-mid+1, mid)*mid;
for (ll i=0; i<mx/mn; i++){
for (ll j=0; j<mn-mid; j++){
res.push_back(lc/(mn-mid+1));
}
for (ll j=0; j<mid; j++){
res.push_back(-lc/mid);
}
}
for (ll i=0; i<mn-mid; i++){
res.push_back(lc/(mn-mid+1));
}
}else{
ll lc = (mn-mid)/__gcd(mn-mid, mid+1)*(mid+1);
for (ll i=0; i<mx/mn; i++){
for (ll j=0; j<mn-mid; j++){
res.push_back(-lc/(mn-mid));
}
for (ll j=0; j<mid; j++){
res.push_back(lc/(mid+1));
}
}
for (ll i=0; i<mn-mid; i++){
res.push_back(-lc/(mn-mid));
}
}
if (mn!=n){
for (auto &ch:res) ch=-ch;
}
cout << res.size() << ln;
for (auto ch:res) cout << ch << " ";
cout << ln;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
auto start = chrono::high_resolution_clock::now();
ll t=1;
cin >> t;
while (t--) solve();
#ifdef LOCAL
auto duration = chrono::duration_cast<chrono::microseconds>(chrono::high_resolution_clock::now() - start);
cout << setprecision(0) << fixed << "time: " << (double)duration.count()/1000.0 << " milliseconds" << endl;
#endif
}
# | 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... |