Skip to content

Instantly share code, notes, and snippets.

@jongha
Created May 12, 2019 13:19
Show Gist options
  • Save jongha/17e0c4d049deaea2cb806c0a81e06e8b to your computer and use it in GitHub Desktop.
Save jongha/17e0c4d049deaea2cb806c0a81e06e8b to your computer and use it in GitHub Desktop.
import java.io.PrintWriter;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
new Main().go();
}
private void go() {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out, true);
while (in.hasNextInt()) {
int max = 0;
int s = in.nextInt();
int e = in.nextInt();
for (int i = Math.min(s, e); i <= Math.max(s, e); i++) {
int n = i;
int count = 0;
while (n != 1) {
n = (n % 2 == 1) ? 3 * n + 1 : n / 2;
++count;
}
++count;
if (count > max)
max = count;
}
out.printf("%d %d %d\n", s, e, max);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment