結果

問題 No.648  お や す み 
ユーザー Fu_L
提出日時 2020-09-28 01:44:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 692 bytes
コンパイル時間 1,590 ms
コンパイル使用メモリ 166,940 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-06-30 17:48:39
合計ジャッジ時間 3,626 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 84
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
int main(void){
    unsigned long long n;
    cin>>n;
    n*=2;
    unsigned long long l=0,r=10000000000;
    while(r-l>1){
        unsigned long long m=(l+r)/2;
        if(m*(m+1)<n){
            l=m;
        }else if(m*(m+1)>n){
            r=m;
        }else{
            cout<<"YES"<<endl;
            cout<<m<<endl;
            return 0;
        }
    }
    if(l*(l+1)==n){
        cout<<"YES"<<endl;
        cout<<l<<endl;
        return 0;
    }
    if(r*(r+1)==n){
        cout<<"YES"<<endl;
        cout<<r<<endl;
        return 0;
    }
    cout<<"NO"<<endl;
    
}
0