D. Number into Sequence【1300】

D. Number into Sequence

time limit per test

3 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an integer nn (n>1n>1).

Your task is to find a sequence of integers a1,a2,…,aka1,a2,…,ak such that:

  • each aiai is strictly greater than 11;
  • a1⋅a2⋅…⋅ak=na1⋅a2⋅…⋅ak=n (i. e. the product of this sequence is nn);
  • ai+1ai+1 is divisible by aiai for each ii from 11 to k−1k−1;
  • kk is the maximum possible (i. e. the length of this sequence is the maximum possible).

If there are several such sequences, any of them is acceptable. It can be proven that at least one valid sequence always exists for any integer n>1n>1.

You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1≤t≤50001≤t≤5000) — the number of test cases. Then tt test cases follow.

The only line of the test case contains one integer nn (2≤n≤10102≤n≤1010).

It is guaranteed that the sum of nn does not exceed 10101010 (∑n≤1010∑n≤1010).

Output

For each test case, print the answer: in the first line, print one positive integer kk — the maximum possible length of aa. In the second line, print kk integers a1,a2,…,aka1,a2,…,ak — the sequence of length kk satisfying the conditions from the problem statement.

If there are several answers, you can print any. It can be proven that at least one valid sequence always exists for any integer n>1n>1.

Example

input

Copy

4
2
360
4999999937
4998207083

output

Copy

1
2 
3
2 2 90 
1
4999999937 
1
4998207083 

=========================================================================

每个数都能写成质因数分解的形式,每个质因数之间互质,所以必须利用一个出现次数最多的质因数,让它尽量单个铺展开,留下一个把剩下全部质因数都给包装成该质因数倍数的形式即可。

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int id=0,ans=0;

void init(ll x)
{
    id=0;
    ans=0;

    for(ll i=2;i*i<=x;i++)
    {
        if(x%i==0)
        {
            int cnt=0;
            while(x%i==0)
            {
               x/=i;
               cnt++;
            }

            if(ans<cnt)
            {
                ans=cnt;
                id=i;
            }

        }
    }

    if(x>1)
    {
        if(ans<1)
        {
            ans=1;
            id=x;
        }
    }
}


int main()
{

  int t;

  cin>>t;

  while(t--)
  {
      ll n;

      cin>>n;

      init(n);
      ll pre=1;
      cout<<ans<<endl;

      for(int i=1;i<ans;i++)
      {
          cout<<id<<" ";
          pre*=id;
      }
      cout<<n/pre<<endl;
  }

    return 0;
}

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qinsanma and Code

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值