Some projects--monkeys eat peach problem

Source: Internet
Author: User

Title Description
The monkey eats the peach question. 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 the remaining peaches and ate one more. Every morning after eating the rest of the day half of the zero one. When I want to eat in the morning of the nth day, I see only one peach left. Find out how many peaches you picked on the first day.


Total Peaches

Sample input
Sample output


#include <iostream>usingnamespacestd;int main(){    int n,i,m=1;    cin>>n;    for(i=n-1;i>0;i--)        m=(m+1)*2;    cout<<m;    return0;}

Purely mathematical problem, but my maths is not good ....

Some projects--monkeys eat peach problem

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: 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.