8.E - 分解质因子

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

InputcopyOutputcopy
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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值