# How to get to the efficient solution of a problem on buying with exchange policy

I was working through some coding challenges at hackerrank.com and got to this one.

I understand the problem and how to solve it, but after solving it I searched for more solutions to improve mine. So I found this.

After explaining the naive method, which is the one that I used, then there is the efficient solution. But I can not understand the explanation that goes from the naive method to the efficient solution.

Can someone help me understand how is the logic to get to the efficient solution:

In above naive implementation, we noticed that after finding initial number of chocolates, we recursively divide the number of chocolates with the number of wrappers required. until we left with 1 chocolate or wrapper. We are recomputing the values i.e. ((choc/wrap + choc%wrap)/wrap until we get 1. It is observed that, we can get the result by just reducing the values of chocolates and wrappers by 1 and then divide them to get the result (choc-1)/(wrap-1)