結果
問題 |
No.634 硬貨の枚数1
|
ユーザー |
![]() |
提出日時 | 2019-06-22 15:02:31 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 121 ms / 2,000 ms |
コード長 | 977 bytes |
コンパイル時間 | 3,995 ms |
コンパイル使用メモリ | 102,272 KB |
実行使用メモリ | 17,920 KB |
最終ジャッジ日時 | 2024-12-26 09:02:52 |
合計ジャッジ時間 | 11,051 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; 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); } }