結果

問題 No.887 Collatz
ユーザー MaboyMaboy
提出日時 2021-06-18 18:54:26
言語 Swift
(5.10.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 234 bytes
コンパイル時間 9,669 ms
コンパイル使用メモリ 125,144 KB
実行使用メモリ 7,760 KB
最終ジャッジ日時 2023-09-04 18:49:42
合計ジャッジ時間 11,123 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,492 KB
testcase_01 AC 3 ms
7,520 KB
testcase_02 AC 4 ms
7,524 KB
testcase_03 AC 3 ms
7,644 KB
testcase_04 AC 3 ms
7,744 KB
testcase_05 AC 3 ms
7,672 KB
testcase_06 AC 3 ms
7,688 KB
testcase_07 AC 3 ms
7,512 KB
testcase_08 AC 3 ms
7,596 KB
testcase_09 AC 3 ms
7,724 KB
testcase_10 AC 4 ms
7,652 KB
testcase_11 AC 3 ms
7,496 KB
testcase_12 AC 3 ms
7,760 KB
testcase_13 AC 4 ms
7,760 KB
testcase_14 AC 3 ms
7,580 KB
testcase_15 AC 3 ms
7,536 KB
testcase_16 AC 3 ms
7,732 KB
testcase_17 AC 3 ms
7,652 KB
testcase_18 AC 3 ms
7,628 KB
testcase_19 AC 3 ms
7,564 KB
testcase_20 AC 3 ms
7,668 KB
testcase_21 AC 3 ms
7,564 KB
testcase_22 AC 3 ms
7,592 KB
testcase_23 AC 3 ms
7,584 KB
testcase_24 AC 4 ms
7,532 KB
testcase_25 AC 4 ms
7,592 KB
testcase_26 AC 3 ms
7,636 KB
testcase_27 AC 3 ms
7,696 KB
testcase_28 AC 3 ms
7,500 KB
testcase_29 AC 3 ms
7,600 KB
testcase_30 AC 4 ms
7,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

let n = Int(readLine()!)!
var l = [n]
while l[l.endIndex - 1] != 1{
    if l[l.endIndex - 1] % 2 == 0{
        l += [l[l.endIndex - 1] / 2]
    }else{
        l += [l[l.endIndex - 1] * 3 + 1]
    }
}
print(l.count - 1)
print(l.max()!)
0