View Code of Problem 3700

#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{
	while(cin>>n && n!= 0) {
		string s="";
		for(int a=n;a>0;a/=2) {
			s+=(a%2?'1':'0');
		}
//		cout<<s<<endl;
		reverse(s.begin(),s.end());
//		cout<<s<<endl;
		int pos = s.rfind("1");
//		cout<<pos<<endl;
		int num=(int)pow(2,s.size()-pos-1);
		
		cout<<num<<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3700