#include<bits/stdc++.h> using namespace std; typedef long long ll; int main (){ int n; while(~scanf("%d", &n)&&n){ int a[1010], cnt = 0; while(n>0){ a[cnt++] = n%2; n /= 2; } int s = 0, t = 0; for(int i = 0;i < cnt;i++){ if(a[i]==0){ s += a[i]*pow(2, t); t++; }else if(a[i]==1){ s += a[i]*pow(2, t); break; } } printf("%d\n", s); } return 0; } |
Double click to view unformatted code.