题解 | 连分数
连分数
https://www.nowcoder.com/practice/8e225697ad4043b5a2669f890ae90974
#include<bits/stdc++.h>
using namespace std;
int T;
int p,q;
inline string work(int x,int y)
{
if(x%y == 0) return to_string(x/y);
int tmp = x/y;
x %= y;
if(y%x == 0) return to_string(tmp) + "+1/" + work(y,x);
else return to_string(tmp) + "+1/" + "{" + work(y,x) +"}";
}
inline void solve()
{
cin>>p>>q;
cout<<p<<'/'<<q<<" = "<<work(p,q)<<'\n';
}
int main()
{
cin>>T;
while(T--) solve();
return 0;
}
