View Code of Problem 3700

#include <iostream>
using namespace std;
int main(){
	int k;
	while(cin>>k){
		if(k==0)
			break;
		int n=k,sum=0,p=1;
		while(n){
			sum=sum+(n%2)*p;
			if(n%2==1)
				break;
			p*=2;
			n/=2;
		}
		cout<<sum<<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3700