1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import java.util.Scanner; import java.util.Arrays; /** * UVA100 */ public class UVA100 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long[] num = new long[2]; while (sc.hasNext()) { num[0] = sc.nextLong(); num[1] = sc.nextLong(); long start = num[0], end = num[1]; if (num[0] > num[1]) { start = num[1]; end = num[0]; } int max = 0; for (long i = start; i <= end; i++) { long n = i; int times = 0; while (n != 1) { if (n % 2 == 0) n /= 2; else n = 3 * n + 1; times++; } if (times + 1 > max) max = times + 1; } System.out.printf("%d %d %d\r\n", num[0], num[1], max); } sc.close(); } } |