仍然是公式求解:

a/b = 1/(p1+1) + (a-r1)/b*(p1+1)

其中:

p1 = b/a

r1 = b%a

更新:

a = a-r1

b = b*(p1+1)

终止循环条件:

  1. a==1:

除到头了,t=a/b

  1. b%a==0:

a 可以被 b 整除,这个时候 t =1 /(b/a) = 1/ p1

while True:
    try:
        a,b = list(map(int,input().split('/')))
        flag = True
        t=[]
        while flag:
            p = int(b/a)
            r = int(b%a)
            if r==0 and a > 1:
                t.append('1'+'/'+ str(p))
                flag=False
            elif a==1:
                t.append('1'+'/'+ str(b))
                flag = False
            else:
                t.append('1'+'/'+ str(p+1))
                a = a-r
                b = b*(p+1)
        print("+".join(t))
                
    except:
        break