結果

問題 No.887 Collatz
ユーザー GodNegotoGodNegoto
提出日時 2019-11-07 14:14:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 456 bytes
コンパイル時間 5,795 ms
コンパイル使用メモリ 71,560 KB
実行使用メモリ 39,948 KB
最終ジャッジ日時 2023-10-13 02:59:08
合計ジャッジ時間 11,587 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 120 ms
39,232 KB
testcase_01 AC 122 ms
39,156 KB
testcase_02 AC 122 ms
39,436 KB
testcase_03 AC 125 ms
39,140 KB
testcase_04 AC 122 ms
39,048 KB
testcase_05 AC 124 ms
39,764 KB
testcase_06 AC 123 ms
39,820 KB
testcase_07 AC 122 ms
39,364 KB
testcase_08 AC 122 ms
39,124 KB
testcase_09 AC 126 ms
39,388 KB
testcase_10 AC 127 ms
39,520 KB
testcase_11 AC 124 ms
39,260 KB
testcase_12 AC 124 ms
39,344 KB
testcase_13 AC 124 ms
39,596 KB
testcase_14 AC 125 ms
39,944 KB
testcase_15 AC 125 ms
39,292 KB
testcase_16 AC 124 ms
39,440 KB
testcase_17 AC 125 ms
39,948 KB
testcase_18 AC 126 ms
39,500 KB
testcase_19 AC 126 ms
39,764 KB
testcase_20 AC 124 ms
39,264 KB
testcase_21 AC 124 ms
39,620 KB
testcase_22 AC 125 ms
39,564 KB
testcase_23 AC 125 ms
39,620 KB
testcase_24 AC 125 ms
39,772 KB
testcase_25 AC 123 ms
39,252 KB
testcase_26 AC 124 ms
39,448 KB
testcase_27 AC 127 ms
39,492 KB
testcase_28 AC 128 ms
39,528 KB
testcase_29 AC 125 ms
39,032 KB
testcase_30 AC 126 ms
39,272 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package algo;

import java.util.Scanner;

//import algo.*;

public class sample7 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int cnt = 0;
		int max = n;
		while (n != 1) {
			if(n % 2 == 0) {
				n = n / 2;
				
			}
			else {
				n = 3 * n + 1;
			}
			cnt++;
			max = Math.max(max, n);
		}
		System.out.println(cnt);	
		System.out.println(max);
	}
}

0