- C++
C0009优秀的拆分 非常简单!!!
- 2024-11-22 16:16:07 @
#include <bits/stdc++.h> using namespace std; int n; int powe[1000]; int cnt; int main() { cin>>n; if(n%2!=0){ cout<<"-1"; return 0; } int b=n; int max=1; while(pow(2,max)<=n){ max++; } for(int i=max;i>=1;i--){ if(pow(2,i)<=b){ powe[cnt]=i; b-=pow(2,i); cnt++; } } if(b==0){ for(int i=0;i<cnt;i++){ cout<<(int)pow(2,powe[i])<<' '; } } else cout<<"-1"; return 0; }
2 条评论
-
施天乐 AK LV 7 @ 2024-12-8 20:52:30
这么智障的题,想必所有人都会吧 -
2024-11-22 16:17:42@
6
- 1