题解 | #将真分数分解为埃及分数#
将真分数分解为埃及分数
http://www.nowcoder.com/practice/e0480b2c6aa24bfba0935ffcca3ccb7b
from fractions import Fraction while True: try: target = Fraction(input()) mother = target.denominator l = [] #存放埃及分母 n=2 while target.numerator != 1: if target > Fraction(1,n): l.append(str(n)) target = target - Fraction(1,n) if n >= mother: n += mother else: n += 1 l.append(str(target.denominator)) print('1/'+'+1/'.join(l)) except: break # #本题说写出一种分解方法即可。所以8/11可以分解为8个1/11相加 # import sys # while True: # try: # z,m = list(map(int, input().split('/'))) # res = ["1/" + str(m) for _ in range(z)] # print("+".join(res)) # except: # # print(sys.exc_info()) # break