问题
代码
/*
* problem: 埃及分数
* method: 贪心法
* date: 2020/05/11
*/
#include<iostream>
using namespace std;
int CommFactor(int a,int b) {
int c=b;
while(a%b){
c=a%b;
a=b;
b=c;
}
return c;
}
void EgyptFactor(int a,int b) {
int e,r;
while(a>1) {
e=b/a+1;
cout<<"1/"<<e<<"+";
a=a*e-b;
b=b*e;
r=CommFactor(a,b);
if(r>1){
a/=r;
b/=r;
}
}
cout<<"1/"<<b<<endl;
}
int main() {
EgyptFactor(7,8);
return 0;
}