結果

問題 No.887 Collatz
ユーザー tonyu0
提出日時 2020-03-17 19:05:29
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 721 bytes
コンパイル時間 19,532 ms
コンパイル使用メモリ 378,584 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-30 22:50:54
合計ジャッジ時間 15,836 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let mut n: usize = itr.next().unwrap().parse().unwrap();
    if n == 1 {
        println!("0");
        println!("1");
    } else {
        let mut max = n;
        let mut one = 0;
        loop {
            if n == 1 {
                println!("{}", one);
                println!("{}", max);
                break;
            }
            if n % 2 == 0 {
                n >>= 1;
            } else {
                n *= 3;
                n += 1;
            }
            max = std::cmp::max(max, n);
            one += 1;
        }
    }


}
0