Codeforces Round #638 (Div. 2) D. Phoenix and Science

Codeforces Round #638 (Div. 2) D. Phoenix and Science

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

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

Every day, some number of bacteria will split (possibly zero or all). When a bacterium of mass m splits, it becomes two bacteria of mass m2 each. For example, a bacterium of mass 3 can split into two bacteria of mass 1.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 n. 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 t (1≤t≤1000) — the number of test cases.

The first line of each test case contains an integer n (2≤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 n, print -1. Otherwise, print two lines.

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

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

If there are multiple solutions, print any.

Example

input

3
9
11
2

output

3
1 0 2 
3
1 1 2
1
0 

构造题~
一开始看题目完全没思路,看了题解发现真的是太妙了😱
我们不难发现某天如果有 xx 个病毒,那变化的范围恰为 [x,2x][x,2*x],那么题目就可以转化为构造一个数组,使得数组的元素和恰为 nn,而我们发现病毒的变化恰好满足 2 的指数幂,所以只要用 2 的倍数构造数组即可,但注意 n 可能会有剩余,只要将剩余部分插入数组重新排序即可,答案即为数组中相邻元素的差值,AC代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
main(){
    int n,t;
    cin>>t;
    while(t--){
        cin>>n;
        vector<int>ans;
        for(int i=1;i<=n;i*=2) ans.push_back(i),n-=i;
        if(n>0){
            ans.push_back(n);
            sort(ans.begin(),ans.end());
        }
        cout<<ans.size()-1<<endl;
        for(int i=1;i<ans.size();i++) cout<<ans[i]-ans[i-1]<<" ";
        puts("");
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章