結果
| 問題 |
No.648 お や す み
|
| コンテスト | |
| ユーザー |
bluemegane
|
| 提出日時 | 2018-09-08 17:44:11 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 24 ms / 2,000 ms |
| コード長 | 794 bytes |
| コンパイル時間 | 852 ms |
| コンパイル使用メモリ | 107,848 KB |
| 実行使用メモリ | 18,048 KB |
| 最終ジャッジ日時 | 2024-12-16 11:13:45 |
| 合計ジャッジ時間 | 4,713 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 84 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
public class Hello
{
public static void Main()
{
var n = long.Parse(Console.ReadLine().Trim());
if (n == 1) { Console.WriteLine("YES"); Console.WriteLine(1); goto end; }
var res = search(n);
if (res * (res + 1)/2L == n)
{
Console.WriteLine("YES");
Console.WriteLine(res);
}
else Console.WriteLine("NO");
end:;
}
public static long search (long n)
{
var ng = 1L;
var ok = (long)Math.Sqrt(2 * n) + 1;
while (ok - ng > 1)
{
var mid = ng + (ok - ng) / 2L;
if (calc(mid, n)) ok = mid;
else ng = mid;
}
return ok;
}
public static bool calc (long a , long n) => a * (a + 1) / 2 >= n;
}
bluemegane