#include<iostream> #include<algorithm> #include<vector> #include<cstdio> #include<cmath> #include<string.h> using namespace std; typedef long long ll; int main(void) { int n; while (cin >> n) { if (n == 0) break; string t; while (n) { t += n % 2 + '0'; n /= 2; } string str; for (int i = 0; i < t.length(); i++) { if (t[i] == '0') str += t[i]; else if (t[i] == '1') { str += t[i]; break; } } int a = 0; for (int i = 0; i < str.length(); i++) a += (str[i] - '0')*pow(2, i); cout << a << endl; } } |
Double click to view unformatted code.