2-1-7217: Monkeys eat peaches

Source: Internet
Author: User


There are a bunch of peaches on the beach, and N monkeys. The first monkey divided the pile of peaches into an average of N, one more, the monkey threw a lot of one into the sea and took a copy. The second monkey then evenly divided the remaining peaches into n parts, and one more, it also threw a lot of one into the sea, took a copy. Third, fourth 、......, the nth monkey is still the final remaining peach into n parts, throw away one more, and take a copy.
Write the program, enter the number of monkeys n, output the minimum number of peaches on the beach, so that every monkey can eat peaches.

Enter an integer n. Output output The minimum number of peaches on the beach when the number of monkeys is n. The result is guaranteed to be within the int type range. Sample input


Sample output

1#include <stdio.h>2 inta[100001]={0};3 intMain ()4 {5     intn,i,j;6scanf"%d",&n);7I=1; j=1;8      while(i<N)9     {Tena[1]=j*n+1; One         if(a[i]% (n1)==0) A         { -i++; -a[i]=a[i-1]/(n1) *n+1; the         } -         Else -         { -J + +; +I=1; -         } +     } Aprintf"%d\n", A[n]); at     return 0; -}

2-1-7217: Monkeys eat peaches

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.