codeforces1348 D. Phoenix and Science

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;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章