View Code of Problem 3700

#include<stdio.h>
#include<math.h>
int main(){
	int A;
	while(scanf("%d",&A)!=EOF&&A!=0){
	    int k;
	    int a[7];
	    for(int i=0;i<=8;i++){
			a[i]=pow(2,i);		
			if(A<a[i]){
				k=i;
				break;
			}	
		}
		for(int j=k-1;j>=0;j--){
			A=A-a[j];
			if(A<0)
				A=A+a[j];
			if(A==0){
			    printf("%d\n",a[j]); 
				break;
			}
		}
	}
} 

Double click to view unformatted code.


Back to problem 3700