#include<cstdio> #include<cstdlib> #include<cmath> #include<iostream> #include<algorithm> using namespace std; typedef long long ll; int main(){ int n,a[1000],j,k; while(scanf("%d",&n)!=EOF&&n){ j=0; while(n>0){ a[j++]=n%2; n/=2; } int m; for(k=0;k<j;k++){ if(a[k]==1){ m=k; break; } } int b=1,num=0; for(k=0;k<=m;k++){ num=a[k]*b+num; b=2*b; } printf("%d\n",num); } return 0; } |
Double click to view unformatted code.