結果

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

ソースコード

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;
  while (left < right) {
    ll mid = (left + right) / 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