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.
hide comments
sachsri:
2020-01-25 18:40:58
How do we know about the end of the input? |
|
alche_mist02:
2020-01-24 08:03:06
How to get continuous inputs in c++... I didnt get it |
|
ankitkawatia:
2020-01-22 13:08:08
I am getting NZEC runtime error. Though the code runs in my computer. I am using Java language. Can anyone help? |
|
mishra_tara_7:
2020-01-15 15:56:34
Can we do it using bottom-up approach?If yes then what would be max value for the size? |
|
sangmai:
2020-01-14 09:20:53
@dvjpy786 while(cin >> n) {} would do it. |
|
aryan__0406:
2020-01-13 20:36:32
what will be the answer of 1000000000.Though my solution is accepted but i have doubt bcz my answer of this expression is 1000000000.
|
|
sameer_19:
2020-01-07 18:03:19
Apply recursion with memoization . Just get values of 0<=n<1000000 stored in array and then get those values for n>1000000 using recursion. |
|
noob_again:
2019-12-29 12:37:16
AC in one go. ^_^ Solved in JAVA using Hashmap for memorization and one recursive function. |
|
zenitsu:
2019-12-21 18:27:53
mriow is recursion with memoization different from DP . I don't think so !
|
|
dvjpy786:
2019-11-28 19:10:56
how to take input in this?
|
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 |