#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll deep,s[11],ans[11],flag,a,b;
ll gcd(ll x,ll y){
if(y==0)return x;
else return gcd(y,x%y);
}
void dfs(ll a,ll b,int x){
if(x>deep)return;
if(a==1&&b>s[x-1]){
s[x]=b;
if(!flag||s[x]<ans[x])memcpy(ans,s,sizeof(ll)*(deep+1));
flag=1;
return;
}
ll l=max(b/a,s[x-1]+1);
ll r=(deep-x+1)*b/a;
if(flag&&r>=ans[deep])r=ans[deep]-1;
for(ll i=l;i<r;i++){
s[x]=i;
ll gcdd=gcd(a*i-b,b*i);
dfs((a*i-b)/gcdd,b*i/gcdd,x+1);
}
}
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>a>>b;
a/=gcd(a,b),b/=gcd(a,b);
for(deep=1;deep<=10;deep++){
dfs(a,b,1);
if(flag){
for(int i=1;i<=deep;i++)cout<<ans[i]<<' ';
return 0;
}
}
}
RE on #1