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:
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
- 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
- {
- 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<
-
- for(int i=1;i
- {
- cout<<id<<" ";
- pre*=id;
- }
- cout<
- }
-
- return 0;
- }
-
相关阅读:
postgresql源码学习(38)—— 备份还原② - do_pg_start_backup函数
统计和为 K 的子数组个数
食之无味?App Startup 可能比你想象中要简单
CAN总线负载及CANoe查看总线负载率
阿里开源低代码引擎 - Low-Code Engine
极值点偏移练习1
【ansible第一次作业】
探秘C语言数组:解锁高效数据管理与多维空间编程技巧"
想升级macOS Big Sur,但是MacBook内存空间不够该怎么办?
Python os模块
-
原文地址:https://blog.csdn.net/jisuanji2606414/article/details/126196996