結果

問題 No.887 Collatz
ユーザー Tsubo
提出日時 2020-06-17 16:12:45
言語 Nim
(2.2.0)
結果
WA  
実行時間 -
コード長 380 bytes
コンパイル時間 2,801 ms
コンパイル使用メモリ 66,260 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-03 12:16:39
合計ジャッジ時間 3,581 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 WA * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
/home/judge/data/code/Main.nim(2, 8) Warning: imported and not used: 'math' [UnusedImport]
/home/judge/data/code/Main.nim(1, 17) Warning: imported and not used: 'sequtils' [UnusedImport]

ソースコード

diff #

import strutils,sequtils
import math
proc input():string=stdin.readLine

let n0=input().parseInt
var
    n=n0
    n_max=n
    cnt=0

if n==1:
    echo 0
    echo 4
    
elif n==2:
    echo 1
    echo 4

else:
    while n!=1:
        if n mod 2==0:
            n=n div 2

        else:
            n=3*n+1
            n_max=max(n,n_max)
        cnt.inc

    echo cnt
    echo n_max
0