Product of Three Numbers

You are given one integer number nn. Find three distinct integers a,b,ca,b,c such that 2≤a,b,c2≤a,b,c and a⋅b⋅c=na⋅b⋅c=n or say that it is impossible to do it.

If there are several answers, you can print any.

You have to answer tt independent test cases.

Input

The first line of the input contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases.

The next nn lines describe test cases. The ii-th test case is given on a new line as one integer nn (2≤n≤1092≤n≤109).

Output

For each test case, print the answer on it. Print “NO” if it is impossible to represent nn as a⋅b⋅ca⋅b⋅c for some distinct integers a,b,ca,b,c such that 2≤a,b,c2≤a,b,c.

Otherwise, print “YES” and any possible such representation.

Sample Input

5
64
32
97
2
12345

Sample Output

YES
2 4 8
NO
NO
NO
YES
3 5 823

题目大意:

一个数n,如果能分解成abc=n(a,b,c>=2且各不相等),输出YES并输出一个实例,否则输出NO。

解题思路:

暴力枚举出奇迹,先找到最小的数a,再找bc。

代码如下:
#include<iostream> 
#include<algorithm>
#include<cstdio>

using namespace std; 

int main(){
	int t; 
	scanf("%d",&t);
	while(t--) 
	{
		int n,x,a,b,c;
		scanf("%d",&n);
		a=-1;//初始化
		for(x=2;x<=n/x;x++)
		{
			if(n%x==0)
			{
				a=x;break;//整除找到a然后跳出循环
			}
		}
		if(a==-1)
		{
			printf("NO\n");
			continue;
		}
		n/=a;b=-1;
		for (x=a+1;x<n/x;x++)
		{
			if (n%x==0) 
			{
				b=x;c=n/x;//找完最小因子a找b和c
				break;
			}
		}
		if (b==-1) 
		{
			printf("NO\n");
			continue;
		}
		printf("YES\n");
		printf("%d %d %d\n",a,b,c);
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值