#include #include #define MAX (1LL<<32) int main() { bool *sums = new bool[MAX]; memset(sums, 0, MAX*sizeof(*sums)); sums[0] = true; long long total = 0; long long limit = 1; long long n = 0; for (long long v=1;; v++) { while (limit < v+total) { limit *= 2; } bool keep = true; for (long long powerOf2=limit; powerOf2 >= v; powerOf2 /= 2) { if (powerOf2-v=0; o--) { if (sums[o]) { if (o+v>=MAX) { delete[] sums; return 0; } sums[o+v] = true; } } total += v; } } }