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