Python Cinq personnes se partagent le poisson
A, B, C, D et E sont allés pêcher ensemble une nuit. Au petit matin du jour suivant, ils étaient tous épuisés, alors ils ont chacun trouvé un endroit pour dormir.
Lorsque le soleil fut haut, A se réveilla le premier. Il partagea le poisson en cinq portions, jeta le poisson en trop et prit sa part.
B se réveilla en deuxième, partagea aussi le poisson en cinq portions, jeta le poisson en trop et prit sa part. .
C, D et E se sont réveillés à tour de rôle et ont également pris du poisson de la même manière.
Question : combien de poissons ont-ils pêchés au minimum ?
Exemple
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'Il y a {fish} poissons au total')
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'Il y a {fish} poissons au total')
break
fish += 1
if __name__ == '__main__':
main()
Résultat de l'exécution :
总共有3121条鱼Autres extensions