TWOCOINS Help

Can anyone tell how to solve TWOCOINS from July 17?

Are there multiple approaches to solve the problem? Please share them as well.

Thanks.

A thread already exists. https://discuss.codechef.com/questions/105381/two-coins-problem-in-july-2017-long-contest