123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package contest1400;
- import java.io.PrintWriter;
- import java.util.Comparator;
- import java.util.Scanner;
- public class I {
- static Scanner cin = new Scanner(System.in);
- static PrintWriter cout = new PrintWriter(System.out);
- public static void main(String[] args) {
- while (cin.hasNext()) {
- int from = cin.nextInt();
- int to = cin.nextInt();
- int tot = foo(from, to);
- cout.println(String.format("%d %d %d", from, to, tot));
- }
- cout.close();
- cin.close();
- }
- private static int foo(int from, int to) {
- if (from > to) {
- int temp = from;
- from = to;
- to = temp;
- }
- int max = 0;
- for (int n = from; n <= to; ++n) {
- int cur = f(n);
- if (cur > max) max = cur;
- }
- return max;
- }
- private static int f(int n) {
- int step = 1;
- while (n > 1) {
- if (n % 2 == 0)
- n /= 2;
- else n = 3 * n + 1;
- ++step;
- }
- return step;
- }
- }
-
|