結果

問題 No.2479 Sum of Squares
ユーザー bluemeganebluemegane
提出日時 2023-09-22 22:38:54
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 785 ms
コンパイル使用メモリ 110,452 KB
実行使用メモリ 26,068 KB
最終ジャッジ日時 2024-07-08 13:22:54
合計ジャッジ時間 2,266 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 22
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

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