题解 | #将真分数分解为埃及分数#
将真分数分解为埃及分数
https://www.nowcoder.com/practice/e0480b2c6aa24bfba0935ffcca3ccb7b
class xx: def __init__(self): self.ls = [] def k(self, n, m): if m % n == 0: self.ls.append(m // n) else:a a = m // n + 1 # m/n在(a-1,a)区间 即n/m在(1/a,1/(a-1))区间 即n/m =1/a+n/m-1/a=1/a+(n*a-m)/m*a 提出1/a self.ls.append(a) self.k(n * a - m, m * a) while True: try: n, m = map(int, input().split("/")) yy = xx() yy.k(n, m) t = "" for i in yy.ls: t += "+1/" + str(i) print(t[1:]) except: break