module CollatzSequence def solve(n) cnt = 1 loop do if cnt > 50 puts :No break elsif n == 1 cnt += 1 puts :Yes puts cnt break else n = n.even? ? n / 2 : 3 * n + 1 cnt += 2 end end end module_function :solve end n = gets.chomp.to_i CollatzSequence.solve(n)