Help with COINS

Hello

I’m attempting this problem(Code: COINS). This is my solution: https://www.codechef.com/viewsolution/38366742

Can anyone tell me what I am doing wrong?

My logic is: if the sum of n/2+n/3+n/4 is bigger than n, then substitute n by that sum, otherwise, print n.

How many maximum coins can you get for n=24?
I can get 27.
You exchange 24 for 12+8+6=26.
Then you exchange the 12 coin for a 13 coin.

Think about it.

Let’s say your answer is given by f(n).
Then,

f(n)=f(\frac{n}{2})+f(\frac{n}{3})+f(\frac{n}{4})

1 Like

Thanks, I understand my mistake now. :slight_smile:

1 Like