Description
给出一整数
n
,要求给
Input
第一行一整数
T
表示用例组数,每组用例输入一整数
Output
对于每组用例,首先输出拆成数的个数 m(1≤m≤100) ,之后输出这 m 个数字
Sample Input
4
1
2
3
10
Sample Output
1
1
1
2
1
3
2
4 6
Solution
考虑将
Code
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<ctime>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const int INF=0x3f3f3f3f,maxn=105;
int T,res;
ll n,ans[maxn];
void Solve(ll n,ll m)
{
while(n%2==0)n/=2,m*=2;
while(n%3==0)n/=3,m*=3;
if(n==1)
{
ans[res++]=m;
return ;
}
ll t=3;
while(t*3<n)t*=3;
ans[res++]=m*t;
Solve(n-t,m);
}
int main()
{
freopen("distribution.in","r",stdin);
freopen("distribution.out","w",stdout);
scanf("%d",&T);
while(T--)
{
scanf("%I64d",&n);
res=0;
Solve(n,1);
printf("%d\n",res);
for(int i=0;i<res;i++)printf("%I64d%c",ans[i],i==res-1?'\n':' ');
}
return 0;
}