結果

問題 No.887 Collatz
ユーザー ks2mks2m
提出日時 2019-09-20 22:26:00
言語 Java19
(openjdk 21)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 395 bytes
コンパイル時間 2,115 ms
コンパイル使用メモリ 71,344 KB
実行使用メモリ 56,456 KB
最終ジャッジ日時 2023-10-12 19:55:25
合計ジャッジ時間 7,123 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
56,132 KB
testcase_01 AC 123 ms
56,340 KB
testcase_02 AC 123 ms
56,436 KB
testcase_03 AC 123 ms
56,040 KB
testcase_04 AC 123 ms
56,088 KB
testcase_05 AC 122 ms
55,664 KB
testcase_06 AC 120 ms
55,956 KB
testcase_07 AC 119 ms
56,236 KB
testcase_08 AC 120 ms
55,624 KB
testcase_09 AC 121 ms
56,160 KB
testcase_10 AC 122 ms
55,812 KB
testcase_11 AC 124 ms
56,456 KB
testcase_12 AC 122 ms
56,276 KB
testcase_13 AC 120 ms
56,084 KB
testcase_14 AC 120 ms
56,276 KB
testcase_15 AC 120 ms
55,740 KB
testcase_16 AC 120 ms
55,968 KB
testcase_17 AC 122 ms
55,816 KB
testcase_18 AC 120 ms
56,084 KB
testcase_19 AC 122 ms
56,348 KB
testcase_20 AC 121 ms
56,272 KB
testcase_21 AC 125 ms
56,240 KB
testcase_22 AC 122 ms
56,036 KB
testcase_23 AC 122 ms
55,716 KB
testcase_24 AC 122 ms
56,156 KB
testcase_25 AC 122 ms
55,768 KB
testcase_26 AC 120 ms
55,928 KB
testcase_27 AC 121 ms
55,744 KB
testcase_28 AC 120 ms
55,620 KB
testcase_29 AC 121 ms
55,960 KB
testcase_30 AC 120 ms
55,764 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		int i = 0;
		int max = n;
		while (n > 1) {
			if (n % 2 == 0) {
				n /= 2;
			} else {
				n = 3 * n + 1;
			}
			i++;
			max = Math.max(max, n);
		}
		System.out.println(i);
		System.out.println(max);
	}
}
0