結果

問題 No.648  お や す み 
ユーザー 👑 obakyan
提出日時 2019-04-02 23:42:39
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 763 bytes
コンパイル時間 523 ms
コンパイル使用メモリ 71,492 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-12-14 14:02:37
合計ジャッジ時間 2,563 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 84
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstdlib>
#include <cstddef>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <iostream>
#include <iomanip>

int main(void)
{
	long n;
	std::cin >> n;
    long min, max, mid;
    if(n == 1) {std::cout << "YES" << std::endl << 1 << std::endl; return 0; }
    min = 1;
    max = 2000000000;
    while(true){
        mid = (min + max) / 2;
        long tmp = mid * (mid + 1) / 2;
        if(tmp == n){
            std::cout << "YES" << std::endl << mid << std::endl;
            return 0;
        }
        if(max - min <= 1){
            break;
        }
        if(tmp < n){
            min = mid;
        } else {
            max = mid;
        }
    }
    std::cout << "NO" << std::endl;
	return 0;
}
0