Arranging Cup-cakes

qstn: http://www.codechef.com/problems/RESQ

sotn: http://www.codechef.com/viewsolution/5274023

can any point where my approach is going wrong

here is my approach

let the dimension of cake be one_half(length),other_half(width)

let initially cake one_half is 1(i.e length is 1) and other_half(width)=n(full size)

then decrease other_half(width) till it become equal or greater to one_half(length)

answer=mod(other_half-one half)