結果

問題 No.887 Collatz
ユーザー iwa_choco_168
提出日時 2019-12-02 13:31:15
言語 Java
(openjdk 23)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 450 bytes
コンパイル時間 1,844 ms
コンパイル使用メモリ 74,820 KB
実行使用メモリ 41,952 KB
最終ジャッジ日時 2024-11-24 03:07:29
合計ジャッジ時間 6,378 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int max = n;
        int count = 0;
        while(n != 1) {
            count++;
            if(n % 2 == 0) n /= 2;
            else n = 3 * n + 1;
            if(max < n) max = n;
        }
        System.out.println(count);
        System.out.println(max);
    }
}
0