304 North Cardinal St.
Dorchester Center, MA 02124

# Bytelandian gold coins CodeChef Solution

## Problem – Bytelandian gold coins CodeChef Solution

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.

## Bytelandian gold coins CodeChef Solution in C++14

``````#include<bits/stdc++.h>
using namespace std;
long long solve(long long x){
if(x<12)
return x;
return solve(x/2)+solve(x/3)+solve(x/4);
}
int main() {
long long x;
while(cin>>x){
cout<<solve(x)<<endl;
}
return 0;
}
``````

## Bytelandian gold coins CodeChef Solution in Java

``````/* package codechef; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
long n=sc.nextInt();
System.out.println(check(n));
}
}
public static long check(long c){
if(c<=10){
return c;
}else{
return Math.max(c,check(c/2)+check(c/4)+check(c/3));
}

}
}
``````

## Bytelandian gold coins CodeChef Solution in Pypy3

``````d={}
def value(n):
if not n in d:
if n<12:
d[n]=n
else:
d[n]=value(n//2)+value(n//3)+value(n//4)
return d[n]
while True:
try:
n=int(input())
print(value(n))
except:
break``````
##### Bytelandian gold coins CodeChef Solution Review:

In our experience, we suggest you solve this Bytelandian gold coins CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Bytelandian gold coins CodeChef Solution

Find on CodeChef

##### Conclusion:

I hope this Bytelandian gold coins CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Data Science in a business context; there are no prerequisites.

Keep Learning!

More Coding Solutions >>

LeetCode Solutions

Hacker Rank Solutions

CodeChef Solutions