結果

問題 No.648  お や す み 
ユーザー hayashi
提出日時 2019-10-28 13:43:10
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 691 bytes
コンパイル時間 841 ms
コンパイル使用メモリ 102,784 KB
実行使用メモリ 17,664 KB
最終ジャッジ日時 2024-09-14 21:11:38
合計ジャッジ時間 4,581 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 84
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using static System.Console;
namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(ReadLine());
            //等差数列
            //k(k+1)/2 = n
            //√k(k+1) = √2n
            //√k*k < √k(k+1) = √2n < √(K+1)(k+1)
            //k<√2n<k+1
            //(long)√2n → k
            long a = (long)Math.Sqrt(2 * N);
            if(a * (a + 1) / 2 == N)
            {
                WriteLine("YES");
                WriteLine(a);
            }
            else
            {
                WriteLine("NO");
            }
        }
    }
}
0