結果

問題 No.887 Collatz
ユーザー tentententen
提出日時 2020-08-30 22:08:23
言語 Java19
(openjdk 21)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 546 bytes
コンパイル時間 2,929 ms
コンパイル使用メモリ 71,372 KB
実行使用メモリ 56,340 KB
最終ジャッジ日時 2023-08-09 18:47:15
合計ジャッジ時間 7,960 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
56,004 KB
testcase_01 AC 118 ms
55,968 KB
testcase_02 AC 121 ms
56,200 KB
testcase_03 AC 118 ms
55,612 KB
testcase_04 AC 116 ms
56,340 KB
testcase_05 AC 125 ms
55,708 KB
testcase_06 AC 119 ms
55,588 KB
testcase_07 AC 118 ms
55,796 KB
testcase_08 AC 118 ms
55,640 KB
testcase_09 AC 121 ms
56,036 KB
testcase_10 AC 121 ms
55,616 KB
testcase_11 AC 121 ms
55,940 KB
testcase_12 AC 121 ms
55,908 KB
testcase_13 AC 118 ms
56,084 KB
testcase_14 AC 121 ms
55,788 KB
testcase_15 AC 120 ms
56,064 KB
testcase_16 AC 124 ms
55,852 KB
testcase_17 AC 123 ms
55,872 KB
testcase_18 AC 120 ms
55,624 KB
testcase_19 AC 126 ms
55,672 KB
testcase_20 AC 120 ms
55,784 KB
testcase_21 AC 119 ms
55,648 KB
testcase_22 AC 117 ms
56,008 KB
testcase_23 AC 119 ms
55,932 KB
testcase_24 AC 120 ms
55,860 KB
testcase_25 AC 118 ms
56,024 KB
testcase_26 AC 122 ms
55,784 KB
testcase_27 AC 119 ms
55,908 KB
testcase_28 AC 119 ms
56,012 KB
testcase_29 AC 115 ms
56,204 KB
testcase_30 AC 120 ms
54,044 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