#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;
vector<ll> pref;
vector<vector<ll>> A;
bool pos;
void dfs(ll i){
pref[i]=-1;
ll mx=1;
for (auto j:A[i]){
if (pref[j]==-1) {pos=0;}
else{
if (!pref[j]) dfs(j);
mx=max(mx, pref[j]+1);
}
}
pref[i]=mx;
}
bool check(ll n, ll m, ll len){
pref.assign(len+1, 0);
A.assign(len+1, vector<ll>());
for (ll i=1; i<=len; i++){
if (i>=n) A[i-n].push_back(i);
if (i>=m) A[i].push_back(i-m);
}
pos=1;
for (ll i=0; i<=len and pos; i++){
if (!pref[i]) dfs(i);
}
if (pos==0) return 0;
return 1;
}
void solve(){
ll n, m; cin >> n >> m;
ll l=0, r=n+m+n+m;
while (l+1<r){
ll mid = (l+r)/2;
if (check(n, m, mid)) l=mid;
else r=mid;
}
check(n, m, l);
cout << l << ln;
for (ll i=1; i<=l; i++){
cout << pref[i]-pref[i-1] << " ";
}
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... |