Information
- ID
- 6252
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 1
- Tags
- # Submissions
- 51
- Accepted
- 26
- Uploaded By
将1个整数拆分成n个2x。
具题目可得,若n为奇数是无法拆分的。所以输出-1。对于偶数,拆就完了。
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
if(n%2==1){
cout<<-1;
return 0;
}
while(n!=0){
int a=1;
while(a<=n)
a*=2;//找大于
a/=2;
cout<<a<<' ';//输出
n-=a;
}
}
钛铀锈乐
By signing up a ZXOJ universal account, you can submit code and join discussions in all online judging services provided by us.