結果

問題 No.887 Collatz
ユーザー tentententen
提出日時 2020-08-30 22:08:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 546 bytes
コンパイル時間 2,086 ms
コンパイル使用メモリ 73,872 KB
実行使用メモリ 54,416 KB
最終ジャッジ日時 2024-04-27 13:30:41
合計ジャッジ時間 6,243 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 114 ms
53,948 KB
testcase_01 AC 108 ms
54,224 KB
testcase_02 AC 103 ms
52,856 KB
testcase_03 AC 111 ms
54,060 KB
testcase_04 AC 106 ms
53,212 KB
testcase_05 AC 106 ms
54,416 KB
testcase_06 AC 110 ms
54,028 KB
testcase_07 AC 113 ms
54,072 KB
testcase_08 AC 104 ms
53,120 KB
testcase_09 AC 109 ms
54,184 KB
testcase_10 AC 103 ms
53,112 KB
testcase_11 AC 116 ms
54,180 KB
testcase_12 AC 121 ms
53,872 KB
testcase_13 AC 115 ms
54,164 KB
testcase_14 AC 105 ms
53,028 KB
testcase_15 AC 116 ms
54,056 KB
testcase_16 AC 104 ms
52,644 KB
testcase_17 AC 112 ms
53,972 KB
testcase_18 AC 111 ms
54,072 KB
testcase_19 AC 103 ms
52,996 KB
testcase_20 AC 103 ms
53,040 KB
testcase_21 AC 109 ms
53,760 KB
testcase_22 AC 101 ms
53,112 KB
testcase_23 AC 97 ms
52,664 KB
testcase_24 AC 107 ms
53,132 KB
testcase_25 AC 104 ms
53,136 KB
testcase_26 AC 114 ms
53,916 KB
testcase_27 AC 116 ms
53,888 KB
testcase_28 AC 115 ms
52,788 KB
testcase_29 AC 128 ms
54,068 KB
testcase_30 AC 120 ms
53,896 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int max = 0;
    	int min = Integer.MAX_VALUE;
    	for (int i = 0; i < 400; i++) {
    	    max = Math.max(max, n);
    	    if (n == 1) {
    	        min = Math.min(min, i);
    	        break;
    	    }
    	    if (n % 2 == 0) {
    	        n /= 2;
    	    } else {
    	        n = 3 * n + 1;
    	    }
    	}
    	System.out.println(min);
    	System.out.println(max);
    }
}
0