結果

問題 No.680 作れる数
コンテスト
ユーザー ats5515
提出日時 2018-04-27 22:55:37
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 727 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 498 ms
コンパイル使用メモリ 100,700 KB
実行使用メモリ 6,144 KB
最終ジャッジ日時 2026-03-16 02:16:51
合計ジャッジ時間 1,198 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
int calcs(int t) {
	int res = 0;
	while (t > 0) {
		res += t;
		t /= 2;
	}
	return  res;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	if (N == 0) {
		cout << "YES" << endl;
		return  0;
	}
	int u = (int)1000000000;
	cerr << calcs(u) << endl;
	int d = 0;
	while (u - d > 1) {
		int m = (u + d) / 2;
		if (calcs(m) >= N) {
			u = m;
		}
		else {
			d = m;
		}
	}
	if (calcs(u) == N) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}
0