题解 | 将真分数分解为埃及分数

## 分解原理参考https://blog.nowcoder.net/n/8ab21466ce9a4a18b289d31a50b8cb7b?f=comment
## 使用原理中的公式可快速解答本题。谢谢大佬。

while True:
    try:
        a, b = list(map(int, input().split("/")))
        res = []
        while b % a != 0:
            c = 1 + b // a
            res.append("1/{}".format(c))
            a = a - b % a
            b = b * c
        res.append("1/{}".format(b // a))
        print("+".join(res))
    except:
        break

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务