• 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 
    

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

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

    1. #include
    2. using namespace std;
    3. typedef long long int ll;
    4. int id=0,ans=0;
    5. void init(ll x)
    6. {
    7. id=0;
    8. ans=0;
    9. for(ll i=2;i*i<=x;i++)
    10. {
    11. if(x%i==0)
    12. {
    13. int cnt=0;
    14. while(x%i==0)
    15. {
    16. x/=i;
    17. cnt++;
    18. }
    19. if(ans
    20. {
    21. ans=cnt;
    22. id=i;
    23. }
    24. }
    25. }
    26. if(x>1)
    27. {
    28. if(ans<1)
    29. {
    30. ans=1;
    31. id=x;
    32. }
    33. }
    34. }
    35. int main()
    36. {
    37. int t;
    38. cin>>t;
    39. while(t--)
    40. {
    41. ll n;
    42. cin>>n;
    43. init(n);
    44. ll pre=1;
    45. cout<
    46. for(int i=1;i
    47. {
    48. cout<<id<<" ";
    49. pre*=id;
    50. }
    51. cout<
    52. }
    53. return 0;
    54. }

  • 相关阅读:
    37、Docker 安装 RabbitMQ
    文献阅读(37)——使用深度卷积神经网络的增强型糖网检测和分类的方法
    面试了1个月连续失败4次,自动化测试真没想象的那么简单
    GTK构件 --- 文本视图控件GTKtextview
    千古第一文人苏轼的众CP
    代码随想录二刷 Day48
    Hafnium简介和构建
    护网HW面试常问——组件&中间件&框架漏洞(包含流量特征)
    (2022杭电多校三)1011.Taxi(曼哈顿最值+二分)
    1095:数1的个数(信奥)
  • 原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126196996