|
| 1 | +# In Byteland they have a very strange monetary system. |
| 2 | +# |
| 3 | +# Each Bytelandian gold coin has an integer number written on it. A coin n can be exchanged in a bank into |
| 4 | +# three coins: n/2, n/3 and n/4. But these numbers are all rounded down (the banks have to make a profit). |
| 5 | +# |
| 6 | +# You can also sell Bytelandian coins for American dollars. The exchange rate is 1:1. But you can not buy |
| 7 | +# Bytelandian coins. |
| 8 | +# |
| 9 | +# You have one gold coin. What is the maximum amount of American dollars you can get for it? |
| 10 | +# |
| 11 | +# Input |
| 12 | +# The input will contain several test cases (not more than 10). Each testcase is a single line with a number |
| 13 | +# n, 0 <= n <= 1 000 000 000. It is the number written on your coin. |
| 14 | +# |
| 15 | +# Output |
| 16 | +# For each test case output a single line, containing the maximum amount of American dollars you can make. |
| 17 | +# |
| 18 | +# Example |
| 19 | +# Input: |
| 20 | +# 12 |
| 21 | +# 2 |
| 22 | +# |
| 23 | +# Output: |
| 24 | +# 13 |
| 25 | +# 2 |
| 26 | +# You can change 12 into 6, 4 and 3, and then change these into 6ドル+4ドル+3ドル = 13ドル. If you try changing the |
| 27 | +# 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. |
| 28 | +# It is better just to change the 2 coin directly into 2ドル. |
| 29 | + |
| 30 | +import sys |
| 31 | + |
| 32 | +list={} |
| 33 | +def chk(n): |
| 34 | + if n in list.keys(): |
| 35 | + return list[n] |
| 36 | + if n<=2: |
| 37 | + ans = n |
| 38 | + else: |
| 39 | + ans = chk(n//2) + chk(n//3) + chk(n//4) |
| 40 | + if ans<n : ans = n |
| 41 | + list[n] = ans |
| 42 | + return ans |
| 43 | + |
| 44 | +for case in sys.stdin: |
| 45 | + n = int(case) |
| 46 | + print(chk(n)) |
0 commit comments