結果

問題 No.47 ポケットを叩くとビスケットが2倍
ユーザー ふゆふみ🔞ざーめん処理用
提出日時 2015-07-13 16:50:57
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 455 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 54,776 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-08 07:02:31
合計ジャッジ時間 1,023 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>

int sumTatakuT( int n )
{
	if( n < 0 ){
		n = -n;
	}

	int distance = 0;
	bool exponent2 = true;

	if( n < 2 ){
		return distance;
	}
	do{
		++distance;
		if( n % 2 && n > 1 ){
			exponent2 = false;
		}
	} while( ( n /= 2 ) > 1 );

	return ( exponent2 ? distance : distance + 1 );
}

int main()
{
	std::string strn;
	std::cin >> strn;
	int n = std::stoi( strn );
	std::cout << sumTatakuT( n ) << "\n";

	return 0;
}
0