求答案

温宗鑫  •  16天前


求答案


Comments:

include<bits/stdc++.h>

using namespace std; int n,x=1,m,a[30],j=0; int main(void){

//preopen("power.in","r",stdin); 
//preopen("power.oUt","w",stdout); 
cin>>n;
if(n%2!=0){
	cout<<-1<<endl;
}
while(pow(2,x+1)<=n){
	x++;
}
while(x){
	m=pow(2,x);
	if(n>=m){
		n-=m;
		a[j++]=m; 
		if(n==0){
			for(int i=0;i<j;i++){
				cout<<a[i]<<" ";
			}
			return 0;
		}
	}
	x--;
}
return 0;

}


赵冉杰  •  16天前

include<bits/stdc++.h>

using namespace std; int n,x=1,m,a[30],j=0; int main(void){

cin>>n;
if(n%2!=0){
	cout<<-1<<endl;
}

while(pow(2,x+1)<=n){
	x++;
}

while(x){
	m=pow(2,x);
	if(n>=m){
		n-=m;
		a[j++]=m;
		if(n==0){
			for(int i=0;i<j;i++){
				cout<<a[i]<<" ";
			}
				return 0;
		}
	
	}
	x--;
}
return 0;

}


熊东锦  •  16天前

include<bits/stdc++.h>

using namespace std; int n,x=1,m,a[30],j=0; int main(void){

//freopen("power.in","r",stdin);
//freopen("power.in","w",stdout);
cin>>n;
if(n%2!=0){
	cout<<-1<<endl;
}

while(pow(2,x+1)<=n){
	x++;
}

while(x){
	m=pow(2,x);
	if(n>=m){
		n-=m;
		a[j++]=m;
		if(n==0){
			for(int i=0;i<j;i++){
				cout<<a[i]<<" ";
			}
			return 0;
		}
	}
	x--;
}
return 0;

}


蔚蔚  •  16天前

include<bits/stdc++.h>

using namespace std; int n,x=1,m,a[30],j=0; int main(void){

cin>>n;
if(n%2!=0){
	cout<<-1<<endl;
}

while(pow(2,x+1)<=n){
	x++;
}

while(x){
	m=pow(2,x);
	if(n>=m){
		n-=m;
		a[j++]=m;
		if(n==0){
			for(int i=0;i<j;i++){
				cout<<a[i]<<" ";
			}
				return 0;
		}
	
	}
	x--;
}
return 0;

}


熊东锦  •  16天前

请先登录,才能进行评论