• + 11 comments

    I've found out that there is a direct solution (i didn't get it myself, I just found out by searching, I solved the problem with while bucle like almost everybody).

    Code

    money = 10
    
    cost = 2
    
    extra = 2
    
    boughtCandies = money / cost
    
    result = boughtCandies + (boughtCandies - 1) / (extra - 1)
    

    Does anyone know the math basis or where this comes from, or where can I read about this?

    Thanks!