The monkey eats the Peach

Source: Internet
Author: User

Title: The monkey picked a few peaches on the first day, ate half of it immediately, and ate one more. The next morning he ate half of the remaining peaches and ate one more. Every morning after eating the day before the rest of the peach half of the zero one. When I wanted to eat it on the 10th morning, I found that there was only one peach left. Write a program to find out how many peaches were picked on the first day.

This program first to find out the relationship between the variables, that is, the number of peaches and days of the relationship between the two, according to the topic: eat every day the day has a half of the peaches and one more!

Now we begin to think about this question : Set the i=1,2,3 (,...,) the total number of Peaches is ni, the first day the total number of Peaches is N1, the next day the total number of Peaches is n2,......

It is not difficult to find N (i+1) and NI satisfies the following formula: Ni=2n (i+1) +1, thinking here, basically the program comes out, or the idea of recursion:

The results of the operation are as follows:

Thanks for reading, hope to solve your doubts help!

The monkey eats the Peach

Related Article

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.