結果

問題 No.887 Collatz
ユーザー Masaki Kitaguchi
提出日時 2022-01-10 01:35:11
言語 Rust
(1.83.0 + proconio)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 11,267 ms
コンパイル使用メモリ 400,636 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-14 10:39:14
合計ジャッジ時間 12,561 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#[macro_export]
macro_rules! setup {
    { mut $input:ident: SplitWhitespace $(,)? } => {
        use std::io::Read;
        let mut buf = String::new();
        std::io::stdin().read_to_string(&mut buf).unwrap();
        let mut $input = buf.split_whitespace();
    };
}

#[macro_export]
macro_rules! parse_next {
    ($str_iter:expr) => {
        $str_iter.next().unwrap().parse().unwrap()
    };
}

fn main() {
    setup! { mut input: SplitWhitespace };

    let n_0: usize = parse_next!(input);

    let mut i = 0;
    let mut n = n_0;
    let mut n_max = n_0;
    while n != 1 {
        match n % 2 {
            0 => {
                n = n / 2;
            }
            1 => {
                n = 3 * n + 1;
            }
            _ => unreachable!(),
        }
        if n > n_max {
            n_max = n;
        }
        i += 1;
    }
    let i_1 = i;

    println!("{}", i_1);
    println!("{}", n_max);
}
0