题解:P13098 构造大师贝贝
思路
诈骗题目,一不留神就会去想质因数分解做法,然后就做烦了,还不知道到底能不能做出来。
显然,对于任何一个数
易得增加次数不超过
代码实现
#include<bits/stdc++.h>
#define int long long
using namespace std;
int lowbit(int u){return u&-u;}
int x[105];
signed main(){
int T;
scanf("%lld",&T);
while(T--){
int n,top=0;
scanf("%lld",&n);
for(int i=1;;i++){
if((int)(sqrt(n))*(int)(sqrt(n))==n)break;
x[++top]=lowbit(n);
n+=lowbit(n);
}
printf("%lld\n",top);
if(top){
for(int i=1;i<=top;i++)printf("%lld ",x[i]);
printf("\n");
}
}
return 0;
}