D. Phoenix and Science

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Phoenix has decided to become a scientist! He is currently investigating the growth of bacteria.

Initially, on day 11, there is one bacterium with mass 11.

Every day, some number of bacteria will split (possibly zero or all). When a bacterium of mass mm splits, it becomes two bacteria of mass m2m2each. For example, a bacterium of mass 33 can split into two bacteria of mass 1.51.5.

Also, every night, the mass of every bacteria will increase by one.

Phoenix is wondering if it is possible for the total mass of all the bacteria to be exactly nn. If it is possible, he is interested in the way to obtain that mass using the minimum possible number of nights. Help him become the best scientist!

Input

The input consists of multiple test cases. The first line contains an integer tt (1≤t≤10001≤t≤1000) — the number of test cases.

The first line of each test case contains an integer nn (2≤n≤1092≤n≤109) — the sum of bacteria masses that Phoenix is interested in.

Output

For each test case, if there is no way for the bacteria to exactly achieve total mass nn, print -1. Otherwise, print two lines.

The first line should contain an integer dd  — the minimum number of nights needed.

The next line should contain dd integers, with the ii-th integer representing the number of bacteria that should split on the ii-th day.

If there are multiple solutions, print any.

Example

input

Copy

3
9
11
2

output

Copy

3
1 0 2 
3
1 1 2
1
0 

Note

In the first test case, the following process results in bacteria with total mass 99:

  • Day 11: The bacterium with mass 11 splits. There are now two bacteria with mass 0.50.5 each.
  • Night 11: All bacteria's mass increases by one. There are now two bacteria with mass 1.51.5.
  • Day 22: None split.
  • Night 22: There are now two bacteria with mass 2.52.5.
  • Day 33: Both bacteria split. There are now four bacteria with mass 1.251.25.
  • Night 33: There are now four bacteria with mass 2.252.25.

The total mass is 2.25+2.25+2.25+2.25=92.25+2.25+2.25+2.25=9. It can be proved that 33 is the minimum number of nights needed. There are also other ways to obtain total mass 9 in 3 nights.

 

In the second test case, the following process results in bacteria with total mass 1111:

  • Day 11: The bacterium with mass 11 splits. There are now two bacteria with mass 0.50.5.
  • Night 11: There are now two bacteria with mass 1.51.5.
  • Day 22: One bacterium splits. There are now three bacteria with masses 0.750.75, 0.750.75, and 1.51.5.
  • Night 22: There are now three bacteria with masses 1.751.75, 1.751.75, and 2.52.5.
  • Day 33: The bacteria with mass 1.751.75 and the bacteria with mass 2.52.5 split. There are now five bacteria with masses 0.8750.875, 0.8750.875, 1.251.25, 1.251.25, and 1.751.75.
  • Night 33: There are now five bacteria with masses 1.8751.875, 1.8751.875, 2.252.25, 2.252.25, and 2.752.75.

The total mass is 1.875+1.875+2.25+2.25+2.75=111.875+1.875+2.25+2.25+2.75=11. It can be proved that 33 is the minimum number of nights needed. There are also other ways to obtain total mass 11 in 3 nights.

 

In the third test case, the bacterium does not split on day 11, and then grows to mass 22 during night 11.

题意:

现在有一个重量为1的细菌,细菌每天晚上重量都会增加1,1个重量为1的细菌可以分裂为2个重量为0.5的细菌,问最短几天总重量可以达到 n,输出每天的细菌分裂数。

思路:

要注意到细菌分裂不会导致细菌重量增加,只是每天晚上才会增重。设第 i 天的细菌数是 a[i],最少天数为 k 天,那么总重量就是1 + a[1] + a[2] + a[3] + ...... + a[k],a[1] .....a[k]也就是 2,4,8,16……

先找出最大的 k 使得 2^1 + 2^2 + ..... + 2^k <= n,剩余的数和这些2的幂排个序,每天需要分裂的细菌数就是相邻两天的细菌差

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const double eps = 1e-15;
const double PI = acos(-1.0);
const int N = 520;

int main()
{
    int t, n;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d", &n);
        vector<int>ans;
        for(int i = 1; i <= n; i <<= 1)
        {
            ans.push_back(i);
            n -= i;
        }
        if(n)
        {
            ans.push_back(n);
        }
        sort(ans.begin(), ans.end());
        int siz = ans.size() - 1;
        cout<<siz<<'\n';
        for(int i = 0; i < siz; ++i)
        {
            cout<<ans[i + 1] - ans[i];
            if(i < siz - 1)
                cout<<' ';
        }
        cout<<'\n';
        ans.clear();
    }
    return 0;
}