結果
問題 |
No.887 Collatz
|
ユーザー |
![]() |
提出日時 | 2021-04-18 11:00:02 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 879 bytes |
コンパイル時間 | 736 ms |
コンパイル使用メモリ | 103,424 KB |
実行使用メモリ | 17,792 KB |
最終ジャッジ日時 | 2024-07-04 04:25:34 |
合計ジャッジ時間 | 2,178 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using static System.Math; using System; public class Hello { static void Main() { var n0 = int.Parse(Console.ReadLine().Trim()); getAns(n0); } static void getAns(int n0) { var p = 0; var nmax = n0; if (n0 == 1) { Console.WriteLine("0\n1"); return; } var i1 = 1000; while (p++ < 400) { if (n0 % 2 == 0) { n0 /= 2; if (n0 == 1) { i1 = Min(i1, p); Console.WriteLine("{0}\n{1}",i1,nmax); return; } } else { n0 = 3 * n0 + 1; nmax = Max(nmax, n0); } } Console.WriteLine(i1); Console.WriteLine(nmax); } }