#include #include #include using namespace std;

bool isPowerOfTwo(int n) { return (n & (n - 1)) == 0; }

vector excellentPartition(int n) { vector partition; int power = log2(n); while (n > 0 && power >= 0) { int num = pow(2, power); if (n >= num) { partition.push_back(num); n -= num; } power--; } if (n > 0) { partition.clear(); } return partition; }

int main() { int n; cin >> n; if (isPowerOfTwo(n)) { cout << -1 << endl; } else { vector partition = excellentPartition(n); if (partition.empty()) { cout << -1 << endl; } else { for (int i = partition.size() - 1; i >= 0; i--) { cout << partition[i] << " "; } cout << endl; } } return 0;

一般来说一个正整数可以拆分成若干个正整数的和。例如1=110=1+2+3+4等。对于正整数n的一种特定拆分我们称它为优秀的当且仅当在这种拆分下n被分解为了若干个不同的2的正整数次幂。注意一个数x能被表示成2的正整数次幂当且仅当x能通过正整数个2相乘在一起得到。例如10=8+2=2^3+2^1是一个优秀的拆分。但是7=4+2+1=2^2+2^1+2^0就不是一个优秀的拆分因为1不是2的正整数次幂。现

原文地址: http://www.cveoy.top/t/topic/iWzy 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录