結果

問題 No.634 硬貨の枚数1
ユーザー RisenRisen
提出日時 2019-06-22 15:02:31
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 131 ms / 2,000 ms
コード長 977 bytes
コンパイル時間 4,013 ms
コンパイル使用メモリ 95,260 KB
実行使用メモリ 22,844 KB
最終ジャッジ日時 2023-08-27 02:50:03
合計ジャッジ時間 12,629 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
20,768 KB
testcase_01 AC 57 ms
20,692 KB
testcase_02 AC 59 ms
20,604 KB
testcase_03 AC 58 ms
22,736 KB
testcase_04 AC 57 ms
22,816 KB
testcase_05 AC 58 ms
22,684 KB
testcase_06 AC 58 ms
22,632 KB
testcase_07 AC 58 ms
20,628 KB
testcase_08 AC 57 ms
22,676 KB
testcase_09 AC 57 ms
20,660 KB
testcase_10 AC 57 ms
22,704 KB
testcase_11 AC 57 ms
18,560 KB
testcase_12 AC 59 ms
20,732 KB
testcase_13 AC 58 ms
20,732 KB
testcase_14 AC 70 ms
20,604 KB
testcase_15 AC 121 ms
22,760 KB
testcase_16 AC 88 ms
20,612 KB
testcase_17 AC 96 ms
22,684 KB
testcase_18 AC 89 ms
20,736 KB
testcase_19 AC 77 ms
20,760 KB
testcase_20 AC 83 ms
22,684 KB
testcase_21 AC 126 ms
20,736 KB
testcase_22 AC 119 ms
22,668 KB
testcase_23 AC 87 ms
22,680 KB
testcase_24 AC 58 ms
20,696 KB
testcase_25 AC 57 ms
22,752 KB
testcase_26 AC 58 ms
18,580 KB
testcase_27 AC 58 ms
20,812 KB
testcase_28 AC 58 ms
20,720 KB
testcase_29 AC 59 ms
22,644 KB
testcase_30 AC 59 ms
20,624 KB
testcase_31 AC 58 ms
20,832 KB
testcase_32 AC 58 ms
20,824 KB
testcase_33 AC 60 ms
20,636 KB
testcase_34 AC 66 ms
18,688 KB
testcase_35 AC 82 ms
20,712 KB
testcase_36 AC 103 ms
20,892 KB
testcase_37 AC 91 ms
22,736 KB
testcase_38 AC 69 ms
22,712 KB
testcase_39 AC 117 ms
20,668 KB
testcase_40 AC 101 ms
20,736 KB
testcase_41 AC 98 ms
20,780 KB
testcase_42 AC 116 ms
20,568 KB
testcase_43 AC 86 ms
22,748 KB
testcase_44 AC 58 ms
20,640 KB
testcase_45 AC 61 ms
20,732 KB
testcase_46 AC 67 ms
20,768 KB
testcase_47 AC 100 ms
22,708 KB
testcase_48 AC 57 ms
20,668 KB
testcase_49 AC 64 ms
22,676 KB
testcase_50 AC 131 ms
18,720 KB
testcase_51 AC 69 ms
20,772 KB
testcase_52 AC 57 ms
18,740 KB
testcase_53 AC 58 ms
20,892 KB
testcase_54 AC 58 ms
20,820 KB
testcase_55 AC 130 ms
20,724 KB
testcase_56 AC 131 ms
22,724 KB
testcase_57 AC 128 ms
20,620 KB
testcase_58 AC 128 ms
22,720 KB
testcase_59 AC 128 ms
20,700 KB
testcase_60 AC 127 ms
20,728 KB
testcase_61 AC 128 ms
20,896 KB
testcase_62 AC 128 ms
20,660 KB
testcase_63 AC 130 ms
22,844 KB
testcase_64 AC 130 ms
22,676 KB
testcase_65 AC 127 ms
20,672 KB
testcase_66 AC 130 ms
20,680 KB
testcase_67 AC 129 ms
20,736 KB
testcase_68 AC 128 ms
22,776 KB
testcase_69 AC 128 ms
18,876 KB
testcase_70 AC 129 ms
20,608 KB
testcase_71 AC 128 ms
22,836 KB
testcase_72 AC 128 ms
20,720 KB
testcase_73 AC 127 ms
20,736 KB
testcase_74 AC 126 ms
20,772 KB
testcase_75 AC 126 ms
20,676 KB
testcase_76 AC 59 ms
22,652 KB
testcase_77 AC 66 ms
20,668 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections.Generic;
using System.Linq;

public class Solution
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var tri = new List<int>();

        int i = 1;
        while (true)
        {
            var t = i * (i + 1) / 2;
            if (t <= n)
            {
                tri.Add(t);
                Console.Error.WriteLine(t);
            }
            else
            {
                break;
            }
            i++;
        }

        // あらゆる自然数は高々3つの三角数の和で表すことができる
        int count = 3;
        if (tri.Contains(n))
        {
            count = 1;
        }
        else
        {
            foreach (var t in tri)
            {
                if (tri.Contains(n - t))
                {
                    count = 2;
                    break;
                }
            }
        }

        Console.WriteLine(count);
    }
}
0