結果

問題 No.887 Collatz
ユーザー Maboy
提出日時 2021-06-18 18:54:26
言語 Swift
(6.0.3)
結果
AC  
実行時間 8 ms / 2,000 ms
コード長 234 bytes
コンパイル時間 1,952 ms
コンパイル使用メモリ 125,012 KB
実行使用メモリ 9,344 KB
最終ジャッジ日時 2024-06-22 16:35:55
合計ジャッジ時間 3,062 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

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