Description
给定一个正整数 �n,设 �=�1×�2×…��n=p1×p2×…pk,其中 ��pi 均为质数,对 1≤�<�1≤i<k,��≤��+1pi≤pi+1。
可以证明,序列 ��pi 是唯一的。
对每个给定的 �n,请你求出 �1,�2,…��p1,p2,…pk。
Input
本题单测试点内有多组测试数据。
第一行是一个整数,表示测试数据组数 �T。
接下来 �T 行,每行一个整数,表示一组数据的 �n。
Output
对每组数据,输出一行若干个用空格隔开的整数,依次表示 �1,�2,…��p1,p2,…pk。
Sample 1
Inputcopy | Outputcopy |
---|---|
9 2 3 4 5 6 7 8 9 10 | 2 3 2 2 5 2 3 7 2 2 2 3 3 2 5 |
Hint
数据规模与约定
对全部的测试点,保证 1≤�≤101≤T≤10,1≤�≤10121≤n≤1012。
#include<iostream>
#include<string>
#include<algorithm>
#define endl '\n'
#define ll long long
#define int ll
using namespace std;
const int N=1e6+7;
signed main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int temp=n;
for(int i=2;i*i<=n;i++)
{
while(temp%i==0)
{
cout<<i<<' ';
temp/=i;
}
}
if(temp!=1) cout<<temp;
cout<<endl;
}
return 0;
}