integer::W,D,tmp read *,W,D D = MIN(INT(sqrt(REAL(W))+1),D) do while(D.gt.1) tmp = W/(D*D) D = D-1 W = W-tmp end do print '(i0)', W end program