View Code of Problem 3700

#include<bits/stdc++.h>
using namespace std;
int n;
int main() {
	while (cin >> n) {
		if (n == 0)
			break;

		string t;
		while (n) {
			t += n % 2 + '0';
			n /= 2;
		}
		string ans;
		for (int i = 0; i < t.length(); i++) {
			if (t[i] == '0')
				ans += t[i];
			else if (t[i] == '1') {
				ans += t[i];
				break;
			}
		}
		int out = 0;
		for (int i = 0; i < ans.length(); i++)
			out += (ans[i] - '0')*pow(2, i);
		cout << out << endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 3700