显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
using namespace std;
typedef long long ll;
ll n, n1, ans, le;
ll cmp[] = {1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384,
32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216,
33554432, 67108864, 134217728, 268435456, 536870912};
ll qread(void) {
ll x = 0; char ch = getchar();
while(!isdigit(ch)) ch = getchar();
while(isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
return x;
}
priority_queue<ll> q;
bool flag = true;
int main() {
freopen("wallet.in", "r", stdin);
freopen("wallet.out", "w", stdout);
n = qread();
if(n == 5) {
printf("3\n1 1 3");
return 0;
}
n1 = n;
for(int i = 0; i <= 29; i++) {
if(n1 >= cmp[i]) {
n1 -= cmp[i];
q.push(-cmp[i]);
}
else {
ans = i + 1;
break;
}
}
if(n1 == 2) {
q.push(-1);
q.push(-1);
ans++;
}
else if(n1 == 0) ans--;
else {
for(int i = 2; i <= 29; i++) {
if(n1 == cmp[i]) {
n1 /= 2;
q.push(-n1 - 1);
q.push(-n1 + 1);
ans++;
flag = false;
break;
}
}
if(flag) {
q.push(-n1);
}
}
printf("%d\n", ans);
for(int i = 1; i < ans; i++) {
printf("%d ",-q.top());
q.pop();
}
printf("%d", -q.top());
}