python 五人分鱼
a、b、c、d、e 五人在某天夜里合伙去捕鱼,到第二天凌晨时都疲惫不堪,于是各自找地方睡觉。
日上三杆,a 第一个醒来,他将鱼分为五份,把多余的一条鱼扔掉,拿走自己的一份。
b 第二个醒来,也将鱼分为五份,把多余的一条鱼扔掉拿走自己的一份。 。
c、d、e依次醒来,也按同样的方法拿鱼。
问他们至少捕了多少条鱼?
实例
def main():
fish = 1
while true:
total, enough = fish, true
for _ in range(5):
if (total - 1) % 5 == 0:
total = (total - 1) // 5 * 4
else:
enough = false
break
if enough:
print(f'总共有{fish}条鱼')
break
fish += 1
if __name__ == '__main__':
main()
fish = 1
while true:
total, enough = fish, true
for _ in range(5):
if (total - 1) % 5 == 0:
total = (total - 1) // 5 * 4
else:
enough = false
break
if enough:
print(f'总共有{fish}条鱼')
break
fish += 1
if __name__ == '__main__':
main()
运行结果:
总共有3121条鱼
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!