C ++ Huawei OJ monkey peach

Source: Internet
Author: User
Tags cmath

C ++ Huawei OJ monkey peach
[Description]

The old monkey worked hard for a lifetime and left a huge fortune for the group of monkeys-a lot of peaches. The old monkey decided to give the peaches to the little monkey.
When the first monkey came, it divided the peach into five heaps. There were as many as five, but there was one more. It leaves the rest to the Old Monkey and takes a pile of them.
The second monkey came. It divided peaches into five heaps. There were as many as five, but one more. It leaves the other one to the Old Monkey and takes a pile of them.
Later, little monkeys did so. All the remaining peaches are left to the old monkey.

There are n monkeys here. Please write a program to calculate the number of peaches at the beginning and the minimum number of peaches at the end.

 

[Input]

The input includes multiple groups of test data.

Each group of test data includes an integer n (1 ≤ n ≤ 20 ).

The input ends with 0, and the row is not processed.

 

[Output]

Each group of test data corresponds to a row of output.

Contains two integers, a and B.

The minimum number of peaches required at the beginning and the minimum number of peaches obtained by the old monkey at the end.

 

[Example input]
5

1

0

 

[Sample output]

3121 1025

1 1

[Algorithm IDEA]

Evaluate the feature function: a1 = a1-(a1-1)/5; a1 = 1

Formula for test: {an-1 }={ a1-1} q ^ (n-1) = {a1-1} (4/5) ^ (n-1)

 

[Diaosi Code]

# Include

# Include

Int main ()

{

Int n, I;

Int sum, l, t;

While (scanf (% d, & n) = 1 & n)

{

L = 1;

For (I = 1; I

L * = 5;

Sum = 1 + 5 * L-1 );

T = sum;

For (I = 1; I <= n-1; I ++)

T = (t-1)/5*4;

Printf (% d, sum, t + n );

}

Printf (% d, sum, t + n );

Return 0;

}

[Rail Code]

# Include

# Include

Using namespace std;

Int main ()

{

Int n;

Long total_num, old_num;

While (cin> n & n! = 0)

{

Total_num = pow (5, n)-4;

Old_num = n + pow (0.8, n) * pow (5, n)-4;

Cout <

}

Return 0;

}

 

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.