結果

問題 No.648  お や す み 
ユーザー stderr
提出日時 2018-02-09 23:48:52
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 782 bytes
コンパイル時間 692 ms
コンパイル使用メモリ 63,496 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-09 04:34:09
合計ジャッジ時間 2,863 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 69 WA * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
#define ll long long
using namespace std;

ll sum_natural_number(ll s) {
  return s * (s + 1) / 2;
}

int main() {
  ll n;
  cin >> n;
  ll left = 1;
  ll right = n + 1;
  while (left < right) {
    ll mid = left + (right - left) / 2;
    if (n == sum_natural_number(mid)) {
      cout << "YES" << endl;
      cout << mid << endl;
      return 0;
    } else if (n < sum_natural_number(mid)) {
      right = mid;
    } else {
      left = mid + 1;
    }
  }
  cout << "NO" << endl;
  return 0;
}
0