#!/usr/bin/perl
use 5.016;
use warnings;
no warnings
qw(recursion
);
sub _f {
my ($m, $n, $c) = @_;
$c :
_f($m, ((($n >= $m * 2) and ($n % 2 == 0)) ? $n / 2 : $n - 1), $c + 1)
);
}
sub f { _f($_[0], $_[1], 0) }
say f(3, 10);
say f(3, 95);
say f(666, 2014);
IyEvdXNyL2Jpbi9wZXJsCnVzZSA1LjAxNjsKdXNlIHdhcm5pbmdzOwpubyB3YXJuaW5ncyBxdyhyZWN1cnNpb24pOwoKc3ViIF9mIHsKCW15ICgkbSwgJG4sICRjKSA9IEBfOwoKCXJldHVybiAoJG4gPD0gJG0gPwoJCSRjIDoKCQlfZigkbSwgKCgoJG4gPj0gJG0gKiAyKSBhbmQgKCRuICUgMiA9PSAwKSkgPyAkbiAvIDIgOiAkbiAtIDEpLCAkYyArIDEpCgkpOwp9CgpzdWIgZiB7IF9mKCRfWzBdLCAkX1sxXSwgMCkgfQoKc2F5IGYoMywgMTApOwpzYXkgZigzLCA5NSk7CnNheSBmKDY2NiwgMjAxNCk7Cg==