結果

問題 No.634 硬貨の枚数1
ユーザー RisenRisen
提出日時 2018-01-19 21:52:11
言語 C#(csc)
(csc 3.9.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 912 bytes
コンパイル時間 3,387 ms
コンパイル使用メモリ 102,696 KB
実行使用メモリ 22,840 KB
最終ジャッジ日時 2023-08-26 18:33:05
合計ジャッジ時間 11,350 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
18,756 KB
testcase_01 AC 53 ms
20,608 KB
testcase_02 AC 53 ms
22,680 KB
testcase_03 AC 53 ms
20,624 KB
testcase_04 AC 53 ms
20,688 KB
testcase_05 AC 53 ms
20,604 KB
testcase_06 AC 54 ms
20,720 KB
testcase_07 AC 53 ms
22,644 KB
testcase_08 AC 53 ms
22,684 KB
testcase_09 AC 53 ms
20,656 KB
testcase_10 AC 55 ms
22,756 KB
testcase_11 AC 53 ms
20,796 KB
testcase_12 AC 53 ms
20,612 KB
testcase_13 AC 55 ms
20,652 KB
testcase_14 AC 59 ms
22,568 KB
testcase_15 AC 91 ms
20,664 KB
testcase_16 AC 69 ms
20,656 KB
testcase_17 AC 74 ms
20,728 KB
testcase_18 AC 72 ms
20,660 KB
testcase_19 AC 58 ms
20,600 KB
testcase_20 AC 62 ms
20,788 KB
testcase_21 AC 98 ms
20,796 KB
testcase_22 AC 91 ms
18,732 KB
testcase_23 AC 69 ms
22,620 KB
testcase_24 AC 54 ms
20,620 KB
testcase_25 AC 54 ms
22,704 KB
testcase_26 AC 53 ms
22,672 KB
testcase_27 AC 53 ms
20,600 KB
testcase_28 AC 54 ms
20,780 KB
testcase_29 AC 54 ms
20,728 KB
testcase_30 AC 54 ms
20,708 KB
testcase_31 AC 53 ms
22,840 KB
testcase_32 AC 53 ms
20,880 KB
testcase_33 AC 54 ms
22,732 KB
testcase_34 AC 60 ms
20,616 KB
testcase_35 AC 66 ms
20,680 KB
testcase_36 AC 80 ms
20,660 KB
testcase_37 AC 72 ms
22,720 KB
testcase_38 AC 58 ms
20,580 KB
testcase_39 AC 91 ms
20,680 KB
testcase_40 AC 79 ms
20,624 KB
testcase_41 AC 79 ms
22,640 KB
testcase_42 AC 89 ms
20,672 KB
testcase_43 AC 67 ms
20,592 KB
testcase_44 AC 54 ms
20,584 KB
testcase_45 AC 54 ms
20,620 KB
testcase_46 AC 56 ms
20,656 KB
testcase_47 AC 72 ms
20,572 KB
testcase_48 AC 53 ms
20,712 KB
testcase_49 AC 55 ms
20,652 KB
testcase_50 AC 101 ms
20,688 KB
testcase_51 AC 58 ms
20,624 KB
testcase_52 AC 53 ms
20,728 KB
testcase_53 AC 52 ms
20,600 KB
testcase_54 AC 54 ms
22,692 KB
testcase_55 AC 98 ms
22,636 KB
testcase_56 AC 102 ms
20,676 KB
testcase_57 AC 99 ms
20,616 KB
testcase_58 AC 98 ms
22,624 KB
testcase_59 AC 98 ms
20,532 KB
testcase_60 AC 97 ms
20,684 KB
testcase_61 AC 98 ms
22,664 KB
testcase_62 AC 97 ms
20,804 KB
testcase_63 AC 99 ms
22,644 KB
testcase_64 AC 97 ms
22,624 KB
testcase_65 AC 96 ms
20,576 KB
testcase_66 AC 99 ms
22,632 KB
testcase_67 AC 99 ms
20,584 KB
testcase_68 AC 99 ms
22,644 KB
testcase_69 AC 98 ms
20,588 KB
testcase_70 AC 98 ms
20,592 KB
testcase_71 AC 98 ms
20,624 KB
testcase_72 AC 98 ms
22,676 KB
testcase_73 AC 100 ms
20,656 KB
testcase_74 AC 98 ms
22,624 KB
testcase_75 AC 96 ms
20,548 KB
testcase_76 AC 54 ms
20,596 KB
testcase_77 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

class Solution
{
    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);
            }
            else
            {
                break;
            }
            i++;
        }

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

            if(tri.Contains(rem))
            {
                count = 2;
                break;
            }
        }

        Console.WriteLine(count);
    }
}
0