結果

問題 No.634 硬貨の枚数1
ユーザー tnk_stnk_s
提出日時 2018-09-13 14:23:13
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 1,468 bytes
コンパイル時間 3,265 ms
コンパイル使用メモリ 104,116 KB
実行使用メモリ 22,968 KB
最終ジャッジ日時 2023-09-13 19:50:55
合計ジャッジ時間 9,951 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
20,900 KB
testcase_01 AC 56 ms
20,680 KB
testcase_02 AC 56 ms
20,928 KB
testcase_03 AC 56 ms
20,788 KB
testcase_04 AC 56 ms
20,828 KB
testcase_05 AC 56 ms
20,768 KB
testcase_06 AC 56 ms
20,840 KB
testcase_07 AC 57 ms
20,888 KB
testcase_08 AC 56 ms
20,748 KB
testcase_09 AC 57 ms
20,928 KB
testcase_10 AC 57 ms
22,892 KB
testcase_11 AC 57 ms
20,744 KB
testcase_12 AC 56 ms
20,848 KB
testcase_13 AC 56 ms
20,828 KB
testcase_14 AC 56 ms
18,784 KB
testcase_15 AC 56 ms
22,732 KB
testcase_16 AC 55 ms
20,672 KB
testcase_17 AC 56 ms
18,800 KB
testcase_18 AC 56 ms
20,780 KB
testcase_19 AC 56 ms
20,784 KB
testcase_20 AC 56 ms
22,872 KB
testcase_21 AC 56 ms
20,756 KB
testcase_22 AC 57 ms
20,844 KB
testcase_23 AC 56 ms
20,840 KB
testcase_24 AC 57 ms
18,852 KB
testcase_25 AC 56 ms
22,804 KB
testcase_26 AC 56 ms
22,804 KB
testcase_27 AC 56 ms
22,804 KB
testcase_28 AC 56 ms
20,740 KB
testcase_29 AC 57 ms
22,788 KB
testcase_30 AC 56 ms
18,892 KB
testcase_31 AC 56 ms
20,900 KB
testcase_32 AC 56 ms
20,836 KB
testcase_33 AC 57 ms
20,684 KB
testcase_34 AC 56 ms
22,968 KB
testcase_35 AC 56 ms
20,936 KB
testcase_36 AC 58 ms
20,760 KB
testcase_37 AC 57 ms
18,840 KB
testcase_38 AC 56 ms
20,776 KB
testcase_39 AC 57 ms
20,748 KB
testcase_40 AC 56 ms
20,748 KB
testcase_41 AC 55 ms
20,684 KB
testcase_42 AC 56 ms
22,796 KB
testcase_43 AC 56 ms
22,728 KB
testcase_44 AC 55 ms
20,824 KB
testcase_45 AC 56 ms
20,940 KB
testcase_46 AC 56 ms
22,804 KB
testcase_47 AC 55 ms
20,688 KB
testcase_48 AC 57 ms
20,928 KB
testcase_49 AC 57 ms
20,884 KB
testcase_50 AC 56 ms
20,756 KB
testcase_51 AC 56 ms
20,744 KB
testcase_52 AC 56 ms
20,844 KB
testcase_53 AC 55 ms
22,792 KB
testcase_54 AC 56 ms
20,828 KB
testcase_55 AC 57 ms
22,876 KB
testcase_56 AC 56 ms
20,760 KB
testcase_57 AC 56 ms
20,792 KB
testcase_58 AC 56 ms
20,756 KB
testcase_59 AC 57 ms
20,760 KB
testcase_60 AC 56 ms
20,688 KB
testcase_61 AC 57 ms
20,932 KB
testcase_62 AC 56 ms
20,952 KB
testcase_63 AC 56 ms
20,752 KB
testcase_64 AC 56 ms
18,804 KB
testcase_65 AC 56 ms
20,688 KB
testcase_66 AC 56 ms
20,892 KB
testcase_67 AC 57 ms
22,792 KB
testcase_68 AC 56 ms
20,768 KB
testcase_69 AC 56 ms
20,936 KB
testcase_70 AC 56 ms
22,756 KB
testcase_71 AC 56 ms
20,932 KB
testcase_72 AC 56 ms
22,880 KB
testcase_73 AC 56 ms
22,824 KB
testcase_74 AC 56 ms
22,864 KB
testcase_75 AC 56 ms
20,904 KB
testcase_76 AC 56 ms
18,820 KB
testcase_77 AC 56 ms
22,892 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;

namespace practice
{
    class Program
    {
        static int triangleNumber(int k)
        {
            return k * (k + 1) / 2;
        }

        static bool isTriangleNumber(int x)
        {
            double d = Math.Sqrt(2 * x);

            int a = (int)Math.Floor(d);
            int b = (int)Math.Ceiling(d);

            if (a == b)
            {
                return false;
            }

            if (a * b / 2 == x)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        static int countCoins(int x)
        {
            // 三角数かどうか調べる
            if (isTriangleNumber(x))
            {
                return 1;
            }

            // 2つの三角数の和であるかどうかを調べる
            int k = 1;
            while (true)
            {
                int a = triangleNumber(k);

                if (a > x / 2)
                {
                    break;
                }

                if (isTriangleNumber(x - a))
                {
                    return 2;
                }

                k++;
            }

            return 3;
        }
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            string[] t = s.Split(' ');
            int a = int.Parse(t[0]);
            Console.Out.WriteLine(countCoins(a));
        }
    }
}
0