結果

問題 No.887 Collatz
ユーザー takeya_okinotakeya_okino
提出日時 2019-09-28 16:50:51
言語 Java21
(openjdk 21)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 468 bytes
コンパイル時間 2,045 ms
コンパイル使用メモリ 74,384 KB
実行使用メモリ 54,256 KB
最終ジャッジ日時 2024-04-10 10:12:41
合計ジャッジ時間 6,709 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
53,896 KB
testcase_01 AC 116 ms
53,936 KB
testcase_02 AC 105 ms
52,876 KB
testcase_03 AC 110 ms
53,276 KB
testcase_04 AC 117 ms
54,132 KB
testcase_05 AC 117 ms
53,860 KB
testcase_06 AC 115 ms
54,164 KB
testcase_07 AC 108 ms
53,204 KB
testcase_08 AC 109 ms
52,820 KB
testcase_09 AC 104 ms
52,776 KB
testcase_10 AC 120 ms
54,256 KB
testcase_11 AC 120 ms
54,008 KB
testcase_12 AC 115 ms
53,380 KB
testcase_13 AC 112 ms
52,756 KB
testcase_14 AC 116 ms
53,972 KB
testcase_15 AC 109 ms
52,740 KB
testcase_16 AC 110 ms
53,068 KB
testcase_17 AC 105 ms
53,016 KB
testcase_18 AC 108 ms
52,848 KB
testcase_19 AC 110 ms
53,044 KB
testcase_20 AC 119 ms
54,000 KB
testcase_21 AC 119 ms
53,920 KB
testcase_22 AC 117 ms
53,948 KB
testcase_23 AC 111 ms
52,844 KB
testcase_24 AC 109 ms
52,876 KB
testcase_25 AC 104 ms
52,764 KB
testcase_26 AC 115 ms
53,928 KB
testcase_27 AC 107 ms
52,928 KB
testcase_28 AC 102 ms
52,756 KB
testcase_29 AC 111 ms
52,924 KB
testcase_30 AC 105 ms
52,872 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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