結果
| 問題 | 
                            No.648  お や す み 
                             | 
                    
| コンテスト | |
| ユーザー | 
                             beet
                         | 
                    
| 提出日時 | 2018-02-09 22:21:59 | 
| 言語 | C++11(廃止可能性あり)  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 2 ms / 2,000 ms | 
| コード長 | 987 bytes | 
| コンパイル時間 | 1,506 ms | 
| コンパイル使用メモリ | 162,180 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-09-13 20:44:09 | 
| 合計ジャッジ時間 | 3,614 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 84 | 
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = __int128_t;
Int abs128(Int val){return val<0?-val:val;}
ostream &operator<<(ostream &os,Int val){
  if(ostream::sentry(os)){
    __uint128_t tmp=abs128(val);
    char buf[64];
    char *d=end(buf);
    do{
      --d;
      *d=char(tmp%10+'0');
      tmp/=10;
    }while(tmp);
    if(val<0) *--d='-';
    Int len=end(buf)-d;
    if(os.rdbuf()->sputn(d,len)!=len){
      os.setstate(ios_base::badbit);
    }
  }
  return os;
}
istream &operator>>(istream &is,Int &val){
  string s;
  is>>s;
  val=0;
  for(Int i=0;i<(Int)s.size();i++)
    if(isdigit(s[i])) val=val*10+s[i]-'0';
  if(s[0]=='-') val*=-1;
  return is;
}
//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  Int l=0,r=1e12;
  auto calc=[&](Int x){
    return x*(x+1)/2;
  };
  while(l+1<r){
    Int m=(l+r)>>1;
    if(calc(m)<n) l=m;
    else r=m;
  }
  if(calc(r)==n){
    cout<<"YES"<<endl;
    cout<<r<<endl;
  }else{
    cout<<"NO"<<endl;
  }
  return 0;
}
            
            
            
        
            
beet