結果

問題 No.680 作れる数
ユーザー weizenweizen
提出日時 2018-08-01 21:55:59
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 825 bytes
コンパイル時間 627 ms
コンパイル使用メモリ 22,516 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-19 20:50:43
合計ジャッジ時間 1,702 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 0 ms
4,348 KB
testcase_06 AC 0 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 1 ms
4,348 KB
testcase_09 AC 0 ms
4,348 KB
testcase_10 AC 0 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 0 ms
4,348 KB
testcase_13 AC 0 ms
4,348 KB
testcase_14 AC 0 ms
4,348 KB
testcase_15 AC 0 ms
4,348 KB
testcase_16 AC 0 ms
4,348 KB
testcase_17 AC 1 ms
4,348 KB
testcase_18 AC 0 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:25:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |         scanf("%lld",&N);
      |         ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>

int main(){
	//s = 0, t = 0, t*2, t=t+1 | t=t, s=s+t
	//t: 1,2,4,8,16 = 31
	//t: 1,2,4,8,17 = 32
	//t: 1,2,4,9,18 = 34
	//t: 1,2,4,9,19 = 35
	//t: 1,2,5,10,20 = 38
	//t: 1,2,5,10,21
	//t: 1,2,5,11
	//t: 1,2,5,11
	//t: 1,3,6,12
	//t: 1,3,6,12
	//t: 1,3,6,13
	//t: 1,3,6,13
	//t: 1,3,7,14
	//t: 1,3,7,14
	//t: 1,3,7,15,30
	//t: 1,3,7,15,31
	// 2^0+2^1+2^2+2^3+2^4 ~ 2^0-1+2^1-1+2^2-1+2^3-1+2^4-1+2^5-1
	// 2^5-1 ~ 2^6-1-6
	
	long long N;
	scanf("%lld",&N);

	long long tleft=0,tright=1000000000;
	int found = 0;
	while(1){
		if(tright-tleft < 0) break;
		long long t = (tleft+tright)/2;
		long long s = 0;
		long long tmp=t;
		while(tmp){ s += tmp; tmp = tmp/2;}
		if(s < N){
			tleft = t+1;
		}else if(s == N){
			found = 1;
			break;
		}else{
			tright = t-1;
		}
	}

	printf("%s\n",found?"YES":"NO");
}	
0