結果

問題 No.2479 Sum of Squares
ユーザー bluemeganebluemegane
提出日時 2023-09-22 22:38:54
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 69 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 2,011 ms
コンパイル使用メモリ 63,216 KB
実行使用メモリ 22,728 KB
最終ジャッジ日時 2023-09-22 22:38:59
合計ジャッジ時間 4,024 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
20,636 KB
testcase_01 AC 59 ms
22,700 KB
testcase_02 AC 59 ms
22,708 KB
testcase_03 AC 59 ms
20,776 KB
testcase_04 AC 59 ms
20,604 KB
testcase_05 AC 59 ms
20,648 KB
testcase_06 AC 58 ms
18,628 KB
testcase_07 AC 58 ms
20,644 KB
testcase_08 AC 57 ms
20,652 KB
testcase_09 AC 58 ms
20,628 KB
testcase_10 AC 57 ms
20,696 KB
testcase_11 AC 59 ms
20,800 KB
testcase_12 AC 59 ms
22,712 KB
testcase_13 AC 59 ms
22,656 KB
testcase_14 AC 58 ms
20,600 KB
testcase_15 AC 69 ms
18,520 KB
testcase_16 AC 57 ms
18,700 KB
testcase_17 AC 59 ms
20,568 KB
testcase_18 AC 58 ms
20,696 KB
testcase_19 AC 58 ms
18,536 KB
testcase_20 AC 57 ms
22,552 KB
testcase_21 AC 58 ms
20,572 KB
testcase_22 AC 58 ms
18,692 KB
testcase_23 AC 58 ms
22,728 KB
testcase_24 AC 58 ms
20,600 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System.Collections.Generic;
using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var s = long.Parse(Console.ReadLine().Trim());
        getAns(s);
    }
    static long calc (long t)
    {
        var a = (long) Sqrt(t);
        var w = (a + 1) * (a + 1);
        if (w > t)
        {
            var w2 = a * a;
            if (w2 > t) return (a - 1) * (a - 1);
            else return w2;
        }
        else return w;
    }
    static void getAns(long s)
    {
        var ans = new List<long>();
        while (true)
        {
            var w = calc(s);
            ans.Add(w);
            s -= w;
            if (s == 0) break;
        }
        Console.WriteLine(ans.Count);
        Console.WriteLine(string.Join(" ",ans));
    }
}
0