Python Five People Dividing Fish

Python3 Examples

A, B, C, D, and E went fishing together one night. By the early morning of the next day, they were all exhausted, so they each found a place to sleep.

When the sun was high up, A woke up first. He divided the fish into five portions, threw away the one extra fish, and took his own share.

B woke up second, also divided the fish into five portions, threw away the one extra fish, and took his own share. .

C, D, and E woke up in turn and also took fish in the same way.

Question: how many fish did they catch at least?

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:
            print(f'There are {fish} fish in total')
            break
        fish += 1


if __name__ == '__main__':
    main()

Execution result:

总共有3121条鱼

Python3 Examples

Other Extensions