結果

問題 No.648  お や す み 
ユーザー yuppe19 😺
提出日時 2020-08-19 17:40:45
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 330 bytes
コンパイル時間 196 ms
コンパイル使用メモリ 27,392 KB
最終ジャッジ日時 2025-01-13 03:52:53
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 84
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    6 |   u64 n; scanf("%lu", &n);
      |          ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <cstdint>
#include <cstdio>
using u64 = uint64_t;

int main(void) {
  u64 n; scanf("%lu", &n);
  u64 r = 0;
  for(int i=30; i>=0; --i) {
    u64 nr = r + (1UL<<i);
    if(nr * (nr+1) / 2 <= n) { r = nr; }
  }
  if(r * (r+1) / 2 == n) {
    puts("YES");
    printf("%lu\n", r);
  } else {
    puts("NO");
  }
  return 0;
}
0