package The_3n_problem;
import java.util.Scanner;
public class The_3n_1_problem {
public static void main(String[] args) {
Scanner leer = new Scanner(System.in);
int mayor, num1, num2, max, min;
do {
mayor = 0;
num1 = leer.nextInt();
num2 = leer.nextInt();
if (num1 > num2) {
max = num1;
min = num2;
} else {
max = num2;
min = num1;
}
for (int i = min; i <= max; i++) {
if (get3n(i) > mayor) {
mayor = get3n(i);
}
}
System.out.println(num1 + " " + num2 + " " + mayor);
} while (leer.hasNext());
}
static int get3n(int n) {
int cont = 1;
while (n != 1) {
cont++;
if (n % 2 != 0) {
n = n * 3 + 1;
} else {
n = n / 2;
}
}
return cont;
}
}
No hay comentarios:
Publicar un comentario