結果

問題 No.1168 Digit Sum Sequence
コンテスト
ユーザー tanson
提出日時 2026-01-08 00:40:55
言語 Standard ML
(MLton 20210117)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 645 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,117 ms
コンパイル使用メモリ 708,364 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2026-01-08 00:41:03
合計ジャッジ時間 4,613 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

fun readLargeInt () =
    valOf (TextIO.scanStream (LargeInt.scan StringCvt.DEC) TextIO.stdIn)


fun int_to_digits n =
    let
        fun int_to_digits_aux nn l =
            if nn > 0 then int_to_digits_aux (nn div 10) ((nn mod 10) :: l)
            else l
    in
        int_to_digits_aux n []
    end


fun findAns n =
    let
        val digits = int_to_digits n
    in
        if List.length digits = 1 then List.hd digits
        else findAns (List.foldl (fn (d, acc) => d + acc) 0 digits)
    end


val () =
    let
        val n = readLargeInt ()

        val ans = findAns n
    in
        print (LargeInt.toString ans ^ "\n")
    end
0