$0 = 0 # ok $1 = N / K $1 = $1 + 1 # ng $2 = $1 - $0 # dif while $2 > 1 $3 = $0 + $1 $3 = $3 / 2 # mid $4 = $3 * $3 $5 = K * N $5 = $5 * $3 $4 = $4 + $5 $5 = N * N if $4 <= $5 $0 = $3 end if $4 > $5 $1 = $3 end $2 = $1 - $0 end $0 = $0 + N return $0