結果

問題 No.2479 Sum of Squares
ユーザー 👑 kakel-sankakel-san
提出日時 2023-09-24 23:11:00
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 61 ms / 2,000 ms
コード長 1,006 bytes
コンパイル時間 1,588 ms
コンパイル使用メモリ 65,676 KB
実行使用メモリ 22,928 KB
最終ジャッジ日時 2023-09-24 23:11:06
合計ジャッジ時間 5,039 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 57 ms
20,668 KB
testcase_01 AC 58 ms
22,788 KB
testcase_02 AC 58 ms
20,740 KB
testcase_03 AC 58 ms
20,740 KB
testcase_04 AC 58 ms
20,756 KB
testcase_05 AC 58 ms
20,724 KB
testcase_06 AC 58 ms
20,920 KB
testcase_07 AC 59 ms
20,740 KB
testcase_08 AC 61 ms
20,744 KB
testcase_09 AC 61 ms
22,928 KB
testcase_10 AC 61 ms
22,852 KB
testcase_11 AC 60 ms
20,696 KB
testcase_12 AC 60 ms
20,748 KB
testcase_13 AC 60 ms
18,708 KB
testcase_14 AC 61 ms
22,740 KB
testcase_15 AC 61 ms
20,832 KB
testcase_16 AC 61 ms
22,796 KB
testcase_17 AC 60 ms
22,748 KB
testcase_18 AC 59 ms
20,756 KB
testcase_19 AC 59 ms
20,840 KB
testcase_20 AC 59 ms
22,788 KB
testcase_21 AC 61 ms
18,652 KB
testcase_22 AC 59 ms
20,716 KB
testcase_23 AC 59 ms
20,740 KB
testcase_24 AC 59 ms
20,696 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static int NN => int.Parse(ReadLine());
    static long[] NList => ReadLine().Split().Select(long.Parse).ToArray();
    static long[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var s = long.Parse(ReadLine());
        var ans = new List<long>();
        while (s > 0)
        {
            var sq = Square(s);
            ans.Add(sq);
            s -= sq;
        }
        WriteLine(ans.Count);
        WriteLine(string.Join(" ", ans));
    }
    static long Square(long s)
    {
        var ok = 1L;
        var ng = 1_000_000_001L;
        while (ng - ok > 1)
        {
            var mid = (ok + ng) / 2;
            if (mid * mid <= s) ok = mid;
            else ng = mid;
        }
        return ok * ok;
    }
}
0