Submit | All submissions | Best solutions | Back to list |
COINS - Bytelandian gold coins |
In Byteland they have a very strange monetary system.
Each Bytelandian gold coin has an integer number written on it. A coin n can be exchanged in a bank into three coins: n/2, n/3 and n/4. But these numbers are all rounded down (the banks have to make a profit).
You can also sell Bytelandian coins for American dollars. The exchange rate is 1:1. But you can not buy Bytelandian coins.
You have one gold coin. What is the maximum amount of American dollars you can get for it?
Input
The input will contain several test cases (not more than 10). Each testcase is a single line with a number n, 0 <= n <= 1 000 000 000. It is the number written on your coin.
Output
For each test case output a single line, containing the maximum amount of American dollars you can make.
Example
Input: 12 2 Output: 13 2
You can change 12 into 6, 4 and 3, and then change these into $6+$4+$3 = $13. If you try changing the coin 2 into 3 smaller coins, you will get 1, 0 and 0, and later you can get no more than $1 out of them. It is better just to change the 2 coin directly into $2.
Added by: | Tomek Czajka |
Date: | 2005-05-03 |
Time limit: | 9s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: NODEJS PERL6 VB.NET |
Resource: | Purdue Programming Contest Training |
hide comments
|
||||||||||||||
2012-12-25 15:57:26 viraj
the end of input in java is difficult. If anyone could help here. Edit: Managed to find empty input but now I am getting TLE. Last edit: 2012-12-26 05:45:05 |
||||||||||||||
2012-12-22 01:11:31 Philipp Heeg
Test Cases: Input: 42 123 555555 1000000000 Output: 46 144 1298380 4243218150 |
||||||||||||||
2012-12-16 14:47:10 Ranker
To detect the end of input use the EOF condn i.e while(scanf("%lld",&x) != EOF). A simple memoization problem........and take care of data type.........int is not enough! |
||||||||||||||
2012-12-15 12:29:38 Aayush
how do we detect end of input? |
||||||||||||||
2012-11-26 01:22:49 xyb
use unsigned int not int, if you want to get AC. |
||||||||||||||
2012-11-06 14:39:08 Cesar Bretana Glez
Mark, in Cpp, the end of file is while the input != EOF |
||||||||||||||
2012-10-17 12:45:57 Mark
How can I detect end of input? |
||||||||||||||
2012-10-11 13:53:58 Ayush Garg
getting WA can any1 post some test cases i might be missing out pls.. |
||||||||||||||
2012-09-25 02:15:06 Shagun Sodhani
Where are you storing the intermediate results for the inputs like 1,2 etc .I mean array of what type? |
||||||||||||||
2012-09-15 09:07:50 Abhimanyu
tle through recursion ... any suggestions ???? help please .... |