题目描述
分子为1的分数称为埃及分数。现输入一个真分数(分子比分母小的分数,叫做真分数),请将该分数分解为埃及分数。如:8/11 = 1/2+1/5+1/55+1/110。
输入描述:
输入一个真分数,String型
输出描述:
输出分解后的string
输入:
8/11
输出:
1/2+1/5+1/55+1/110
代码如下:
while True:
try:
up,down = list(map(int,input().split("/")))
res = ""
while up != 1:
if down%(up-1) == 0:
res += "1/"+str(down//(up-1))+"+"
up = 1
else:
res += "1/"+str(down//up+1)+"+"
x = up-down%up
down = down*(down//up+1)
up = x
if down%up == 0:
down = down//up
up = 1
res += "1/"+str(int(down))
print(res)
except:
break