結果

問題 No.887 Collatz
ユーザー mame_shibe
提出日時 2019-12-05 02:47:24
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 850 bytes
コンパイル時間 1,788 ms
コンパイル使用メモリ 112,824 KB
実行使用メモリ 26,684 KB
最終ジャッジ日時 2024-12-15 06:26:34
合計ジャッジ時間 4,030 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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.

ソースコード

diff #

using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace YukiCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {
            int n = int.Parse(ReadLine());
            List<int> nList = new List<int>();

            nList.Add(n);

            while (n != 1)
            {
                if (n % 2 == 0)
                {
                    n /= 2;
                }
                else
                {
                    n = (3*n) +1;
                }
                nList.Add(n);
            }

            WriteLine(nList.IndexOf(1));
            WriteLine(nList.Max());


        }
    }
}
0