結果

問題 No.648  お や す み 
ユーザー tnakao0123
提出日時 2018-02-15 20:22:19
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 876 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 84,712 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-13 21:09:27
合計ジャッジ時間 2,676 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 84
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:43:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |   scanf("%lld", &n);
      |   ~~~~~^~~~~~~~~~~~

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 648.cc: No.648  お や す み  - yukicoder
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef long long ll;

/* global variables */

/* subroutines */

/* main */

// x(x+1)/2 = n -> x(x+1)=2n

int main() {
  ll n;
  scanf("%lld", &n);

  ll n2 = n * 2;

  ll x0 = 1, x1 = 2000000000;
  while (x0 + 1 < x1) {
    ll x = (x0 + x1) / 2;
    if (x * (x + 1) <= n2) x0 = x;
    else x1 = x;
  }
  //printf("x0=%lld\n", x0);

  if (x0 * (x0 + 1) == n2) printf("YES\n%lld\n", x0);
  else puts("NO");
  return 0;
}
0