(Circulation exercises) five points monkey peaches

Title: On the beach there are a bunch of peaches, five monkeys to divide this pile first monkey peaches credentials is divided into five parts, one more, one more than the monkey thrown into the sea, he took a second. two monkeys and the rest of the peaches were divided into five, one more, it also put more than one thrown into the sea, took a third, fourth, fifth monkeys are doing asked originally on the beach at least how many peaches?

Idea: You can start from the fifth monkey, pushed back to front. The last monkey divided into five parts of more than one, assuming the last monkey take a peach, and finally there is at least 1 * 5 + 1 = 6 peaches.

Please try to write original program calculates how many peaches.

# Title: On the beach there are a bunch of peaches, five monkeys to divide this pile first monkey peaches credentials is divided into five parts. 
# One more, put more than a monkey thrown into the sea, took a the second monkey and the rest of the peaches were divided into five portions, 
# one more, it also put more than one thrown into the sea, he took a third, fourth, fifth monkeys are to do so, 
# asked on the beach had a minimum of how many peaches? 

# ideas: You can start from the fifth monkey, push from the back. The last monkey divided into five parts of more than one, assuming the last monkey take a peach, and finally there is at least 1 * 5 + 1 = 6 peaches. 

i = 1 # only 5 monkeys take away the number of peaches 
COUNT = 0 # Number of peaches on the beach the rest of 
the while True: 
       COUNT = i * 5 + 1 # before the fifth take only the number of the remaining peaches on the beach 
       for J in the Range (0,4): # inference 4,3,2,1 monkeys circumstances 
            IF cOUNT = 0% 4:!   # number of the remaining peaches must be divisible by 4 
                flag = False                 # In Flag is used to determine the current value of i attempt is successful, unsuccessful attempt to continue 
                i + =. 1 BREAK the else : 
                COUNT = (COUNT /. 4) +. 1. 5 * 
                In Flag = True
        IF In Flag == True:
             Print (COUNT )
             Print (I)
             BREAK
                
            
  

operation result:

3121.0
255

Guess you like

Origin www.cnblogs.com/echo-kid-coding/p/11112753.html