4.4将真分数变为埃及分数
算法流程图
#include<bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
void solve()
{
long long a,b,c;
cin>>a>>b;
while(1)
{
if(b%a)c=b/a+1;
else c=b/a,a=1;
if(a==1)
{
printf("1/%ld\n",c);
break;
}
else printf("1/%ld + ",c);
a=a*c-b;
b=b*c;
if(a==3&&b%2==0)
{
printf("1/%ld + 1/%ld\n",b/2,b);
break;
}
}
}
int main()
{
int t;cin>>t;
while(t--)
{
solve();
}
return 0;
}