program main implicit none integer*8::N,D,tmp,i read *,N,D do i=1,D tmp = i*N if(MOD(tmp,D).eq.0) then print'(i0)',tmp/D-1 return end if end do end program main