Sdut 1232-monkey peach (reverse push)

Source: Internet
Author: User
Monkey peach Time Limit: 1000 ms memory limit: 65536 k any questions? Click Here ^_^ The old monkey suffered a long time 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. 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. Sample Input
510
Sample output
3121 10251 1
X % 5 = 1. Therefore, we can add four peaches to the initial peach heap. (x + 4) /5 (which can be divisible) indicates the pile of old monkeys that the first monkey took with the old monkey. Then there is (x + 4) * (4/5), which is still the case of four peaches above. Then the second monkey took the peaches and finally the nth monkey took them, the remaining peaches are (x + 4) * (4/5) ^ n. The number must be an integer and X should be as small as possible. Therefore, x + 4 = 5 ^ N; X = 5 ^ n-4;
Then the remaining peaches plus the peaches (N in total) left by the old monkey each time and then subtract the four peaches added at the beginning, that is, the remaining peaches of The Old Monkey: 4 ^ N + n-4;
 
#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#include <cctype>#include <cmath>#include <cstdlib>#include <vector>#include <queue>#include <set>#include <map>#include <list>#define ll long longusing namespace std;const int INF = 0x3f3f3f3f;int main(){int n;while(~scanf("%d",&n)&&n){ll x=pow(5,n)-4;ll lef=pow(4,n)+n-4;printf("%lld %lld\n",x,lef);}return 0;}

Sdut 1232-monkey peach (reverse push)

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.