結果
問題 | No.634 硬貨の枚数1 |
ユーザー |
![]() |
提出日時 | 2018-09-13 14:23:13 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 26 ms / 2,000 ms |
コード長 | 1,468 bytes |
コンパイル時間 | 979 ms |
コンパイル使用メモリ | 112,852 KB |
実行使用メモリ | 26,408 KB |
最終ジャッジ日時 | 2024-07-01 04:24:00 |
合計ジャッジ時間 | 5,228 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 75 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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)); } } }