結果
問題 | No.887 Collatz |
ユーザー |
|
提出日時 | 2020-01-05 22:15:15 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 1 ms / 2,000 ms |
コード長 | 556 bytes |
コンパイル時間 | 12,841 ms |
コンパイル使用メモリ | 391,296 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-11-22 23:34:51 |
合計ジャッジ時間 | 13,554 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
use std::io::Read; fn solve(n0: u32) { let mut results = vec![]; results.push(n0); let mut n: u32 = n0; while n > 1 { if n % 2 == 0 { n /= 2; } else { n = 3 * n + 1; } results.push(n); } println!("{}", results.len() - 1); println!("{}", results.iter().max().unwrap()); } fn main() { let mut n0 = String::new(); std::io::stdin().read_to_string(&mut n0).ok(); let n0: u32 = n0.trim().split('\n').next().unwrap().trim().parse::<u32>().unwrap(); solve(n0); }