散读 | 埃及分数和Graham猜想

散读 | 埃及分数和Graham猜想

埃及分数: 古埃及的分数中, 分子只能为1, 比如, 他们没有 3/4, 若要表达 3/4, 则需要表示成 1/4+1/2

from fractions import Fraction


def greedySearch(frac, rstList):
    if frac.numerator == 1 and frac not in rstList:
        return frac
    else:
        return Fraction(1, int(frac.denominator / frac.numerator)+1)


def greedySum2One(initFrac):
    rstList = [initFrac]
    initFrac = 1 - initFrac
    while initFrac != 0:
        rstList.append(greedySearch(initFrac, rstList))
        initFrac -= rstList[-1]
    return rstList


def greedySum2Any(targetFrac):
    rstList = []
    if targetFrac.numerator == 1:
        return rstList.append(targetFrac)
    else:
        remainFrac = targetFrac
        while remainFrac != 0:
            rstList.append(greedySearch(remainFrac, rstList))
            remainFrac -= rstList[-1]
        return rstList


def printResult(rstList, rst):
    denoList = sorted([frac.denominator for frac in rstList])
    for i in denoList[:-1]:
        print('1/{}'.format(i), end=' + ')
    print('1/{} = {}'.format(denoList[-1], rst))


if __name__ == '__main__':
    initDeno = input('(input an integer greater than one)\nThe initial Fraction is 1/')
    result = greedySum2One(Fraction(1, int(initDeno)))
    printResult(result, 1)
    print()
    targetFrac = input('(input any fraction like `&/&`)\nThe target Fraction is ').split('/')
    targetFrac = Fraction(int(targetFrac[0]), int(targetFrac[1]))
    result = greedySum2Any(targetFrac)
    printResult(result, '{}/{}'.format(targetFrac.numerator, targetFrac.denominator))

"""
sample run:

(input an integer greater than one)
The initial Fraction is 1/3
1/2 + 1/3 + 1/6 = 1

(input any fraction like `&/&`)
The target Fraction is 7/15
1/3 + 1/8 + 1/120 = 7/15
"""

Graham猜想: 将大于1的整数任意分成有限个子集,必然有一个子集中的部分整数倒数加起来为1,例如只要有一个子集中有2、3、6,就有1 = 1/2 + 1/3 + 1/6。相关证明见 Thomas Bloom最新证明

参考:
量子位20220313
Erdős–Graham problem - Wikipedia
[2112.03726] On a density conjecture about unit fractions (arxiv.org)
Thomas Bloom (Oxford): A density conjecture about unit fractions - YouTube

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值