View Code of Problem 3700

#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
string bt(int x){
	string a;
	char b;
	while(x){
		b=x%2+'0';
		a=b+a;
		x=x/2;
	}
	return a;
}
int main(){
	string a;
	int b,k,sum;
	while(cin>>b&&b){
		a=bt(b);
		k=0;
		for(int i=a.length()-1;i>=0;i--){
			k++;
			if(a[i]=='1'){
				sum=pow(2,k-1);
				break;
				
			}
		}
		cout<<sum<<endl;
		
		
		
		
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3700