3-p03_monkey_peach五猴分桃



def get_peaches(monkeys):
    peaches=1
    while not distribute(peaches,monkeys):
        peaches +=monkeys#每次加1太慢,可以每次加monkeys
    return peaches
def distribute(peaches,monkeys):
    for _ in range(monkeys):
         peaches -=1
         if peaches % monkeys !=0:
             return False
         peaches =peaches//monkeys * (monkeys-1)
    return True


if __name__ == '__main__':
    print(get_peaches(5))
D:\Anaconda\python.exe D:/AI20/06_codes/deeplearning_20/p03_monkey_peach.py
3121

Process finished with exit code 0

发布了88 篇原创文章 · 获赞 2 · 访问量 1316

猜你喜欢

转载自blog.csdn.net/HJZ11/article/details/104423127