結果

問題 No.648  お や す み 
ユーザー vrjfsyi
提出日時 2018-04-02 07:31:11
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 788 bytes
コンパイル時間 688 ms
コンパイル使用メモリ 66,084 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-09-13 21:19:47
合計ジャッジ時間 2,698 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 84
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <array>
#include <map>
#include <stack>
#include <queue>
#include <set>

using namespace std;

long long calc(long long x) {
    return x * (x + 1) / 2;
}

int main() {

    long long n;
    cin >> n;

    long long a = 1;
    long long b = 2000000000LL;

    long long result = -1;
    while (a <= b) {
        long long c = (a + b) / 2;
        long long x = calc(c);

        if (x == n) {
            result = c;
            break;
        } else if (x < n) {
            a = c + 1;
        } else {
            b = c - 1;
        }

    }

    if (result != -1) {
        cout << "YES" << "\n";
        cout << result << "\n";
    } else {
        cout << "NO" << "\n";
    }


    return 0;
}

0