The One has several rules about cube distribution:
if a family receives at least one cube, every prime divisor (素数除数)of the number of cubes(立方体) received should be either 2 or 3, moreover if one family receives a > 0 cubes and another family in the same year receives b > 0 cubes then a should not be divisible by b and vice versa.
题目大意 :
拆分数字;
然后每个数字由2^x * 3^y 的形式,所以如果 n 可以直接被 2^x * 3^y 整除的话,即 n % (2^x * 3^y) == 0,那么就可以直接输出 n 了。如果不能被直接整除的话,我们可以先将 n 拆解成不能被 3 和 2 整除的形式,这里的话用一个 mul 记录 n 除以多少。
#include<bits/stdc++.h>
using namespace std;
#define maxn 1005
long long a[maxn],cnt,ans[maxn];
void judge(long long x,long long temp)
{
long long y;
while(x%3==0)
{
x/=3;
temp*=3;
}
while(x%2==0)
{
x/=2;
temp*=2;
}
if(x==1)
ans[cnt++]=temp;
else
{
y=3;
while(y*3<x)
{
y*=3;
}
ans[cnt++]=temp*y;;
judge(x-y,temp);
}
}
int main()
{
ios::sync_with_stdio(false);
freopen("distribution.in", "r", stdin);
freopen("distribution.out", "w", stdout);
int t;
cin>>t;
for(int i=0; i<t; i++)
cin>>a[i];
for(int i=0; i<t; i++)
{
cnt=0;
judge(a[i],1);
cout<<cnt<<endl;
for(int j=0; j<cnt; j++)
{
if(j==0)
cout<<ans[j];
else
cout<<" "<<ans[j];
}
cout<<endl;
}
return 0;
}