Python Five People Dividing Fish
A, B, C, D, and E went fishing together one night. By early the next morning they were all exhausted, so each found a place to sleep.
When the sun was high, A woke up first. He divided the fish into five portions, threw away the extra one fish, and took his own portion.
B woke up second, also divided the fish into five portions, threw away the extra one and took his own portion. .
C, D, and E woke up in turn and took fish in the same way.
What is the minimum number of fish they caught?
Example
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:
(
f
'Total fish: {fish}'
)
break
fish +
=
1
if
name
==
'main'
:
main
(
)
Running result:
总共有3121条鱼
Python3 Examples