Python realizes the problem of the monkey's division of Peach

Source: Internet
Author: User
Problem Description:

Five monkeys are divided into peaches. In the middle of the night, the first monkey get up first, it divides the peach into equal five piles, one more. So it ate one and took a bunch; the second monkey got up and looked, only four peaches. So the four piles together, divided into equal five piles, and one more. So, it also ate one, took a bunch of; Some of the other monkeys are divided like this. Q: There are at least as many peaches in this pile.

# #本算法从最后一个猴子进行逆向推倒
 Peach (monkey=5):
    pea = 4  # #最后一个猴子分完剩余的桃子
     1:
        num = Pea
        range (monkey): num = num + num/4 + 1 num% 1!= 0: # #如果分出了小数则结束内层循环 
  
  
            
    15/>pea = 4  # #最后的桃子一定是4的整数倍
                
   
   break num% 1 = 0:  # #如果是整分 End
            
  Break  
    pea, num



   
  ' __main__ ':
    pea, num = Peach ()
    print (pea, num)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.