Problem Description

You are given one integer number n. Find three distinct integers a,b,c such that 2≤a,b,c and a⋅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 t independent test cases.

Input

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

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

Output

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

Otherwise, print "YES" and any possible such representation.

Examples

Input

5
64
32
97
2
12345

Output

YES
2 4 8
NO
NO
NO
YES
3 5 823

题意:t 组数据,每组给出一个数 n,问 n 是否能分解成 a*b*c 的形式,要求 a、b、c 大于等于 2 并且不相等,若存在,输出任意一个方案

思路:

将 n 分解成 a*b*c 的形式,那么 a、b、c 这三个数一定是 n 的因子,因此首先将 n 进行因子分解,并统计其素因子个数,然后判断是否有三个不一样的因子

当 n 存在一个素因子 x 时:最简单的方案是 x * (x*x) * (x*x*x),也即 n 中至少存在 6 个以上的 x 时,才存在合法方案

当 n 存在两个素因子 x1、x2 时:最简单的方案是 (x1*x2)*x1*x2、(x1*x1)*x1*x2、(x2*x2)*x1*x2,也即 n 中的 x1、x2 个数和至少达到 4 个时,才存在合法方案

当 n 存在三个及以上的素因子时,一定存在合法方案

而输出合法方案是一个问题,可以发现,如果有了 a、b,那么 c 就不需要进行暴力枚举,直接利用 c=n/(a*b) 即可计算得出

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
#define Pair pair<int,int>
LL quickPow(LL a,LL b){ LL res=1; while(b){if(b&1)res*=a; a*=a; b>>=1;} return res; }
LL multMod(LL a,LL b,LL mod){ a%=mod; b%=mod; LL res=0; while(b){if(b&1)res=(res+a)%mod; a=(a<<=1)%mod; b>>=1; } return res%mod;}
LL quickMultPowMod(LL a, LL b,LL mod){ LL res=1,k=a; while(b){if((b&1))res=multMod(res,k,mod)%mod; k=multMod(k,k,mod)%mod; b>>=1;} return res%mod;}
LL quickPowMod(LL a,LL b,LL mod){ LL res=1; while(b){if(b&1)res=(a*res)%mod; a=(a*a)%mod; b>>=1; } return res; }
LL getInv(LL a,LL mod){ return quickPowMod(a,mod-2,mod); }
LL GCD(LL x,LL y){ return !y?x:GCD(y,x%y); }
LL LCM(LL x,LL y){ return x/GCD(x,y)*y; }
const double EPS = 1E-6;
const int MOD = 1000000000+7;
const int N = 1000+5;
const int dx[] = {0,0,-1,1,1,-1,1,1};
const int dy[] = {1,-1,0,0,-1,1,-1,1};
using namespace std;map<LL, int> num;   //记录素因子个数
LL factor[N], cntF; //记录素因子
void getFactor(LL n) {cntF = 0;num.clear();for (LL i = 2; i <= n / i; i++) {if (n % i == 0) //记录素因子factor[cntF++] = i;while (n % i == 0) {n /= i;num[i]++; //记录素因子个数}}if (n > 1) {factor[cntF++] = n;num[n]++;}
}
int main() {int t;scanf("%d", &t);while (t--) {LL n;scanf("%lld", &n);getFactor(n);if (cntF == 1) {if (num[factor[0]] >= 6) {LL a = factor[0];LL b = factor[0] * factor[0];LL c = n / (a * b);printf("YES\n");printf("%lld %lld %lld\n", a, b, c);} elseprintf("NO\n");} else if (cntF == 2) {if (num[factor[0]] + num[factor[1]] >= 4) {LL a = factor[0];LL b = factor[1];LL c = n / (a * b);printf("YES\n");printf("%lld %lld %lld\n", a, b, c);} elseprintf("NO\n");} else {LL a = factor[0];LL b = factor[1];LL c = n / (a * b);printf("YES\n");printf("%lld %lld %lld\n", a, b, c);}}return 0;
}

Product of Three Numbers(CF-1294C)相关推荐

  1. 【解题报告】随便练练二(CF 2300)

    [解题报告]随便练练二(CF 2300) A:Antimatter | CF383D 题意 思路 :DP 代码 B:Physical Education Lessons | CF915E 题意 思路一 ...

  2. Commentator problem(CF 2)

    题目链接 题目大意: 给定三个圆,询问是否存在点满足该点与三个圆夹角均相等,若存在多组解返回夹角最大值. 圆外一点到两圆夹角均相等: 即 sina = sinb = r1 / d1 = r2 / d2 ...

  3. Codeforces 446C —— DZY Loves Fibonacci Numbers(线段树)

    题目:DZY Loves Fibonacci Numbers 题意比較简单,不解释了. 尽管官方的题解也是用线段树,但还利用了二次剩余. 可是我没有想到二次剩余,然后写了个感觉非常复杂度的线段树,还是 ...

  4. 1009 Product of Polynomials (25)(25 分)

    题目 原题大意:求两个多项式的数乘 关键单词对照翻译如下: exponent 指数 coefficient 系数 polynomial 多项式 product 数乘 思路 最直接最快速的方法就是使用m ...

  5. POJ1338 Ugly Numbers(解法二)【废除!!!】

    本文废除!!! 参考链接:POJ1338 Ugly Numbers[水题] 问题链接:POJ1338 Ugly Numbers.基础级练习题,用C语言编写程序. 题意简述:不能被2.3和5以外的素数整 ...

  6. uva 138 - Street Numbers(等差数列求和)

    题目链接:138 - Street Numbers 题目大意:找到10组a和b,使得sum[1,a - 1] == sum[a, b]. 解题思路:先用二分做了一遍,枚举b,二分a,但是这样很慢,这能 ...

  7. The 2018 ACM-ICPC上海大都会赛 J Beautiful Numbers (数位DP)

    题意:求小于等于N且能被自己所有位上数之和整除的数的个数. 分析:裸的数位dp.用一个三位数组dp[i][j][k]记录:第i位,之前数位之和为j,对某个mod余数为k的状态下满足条件的个数.这里mo ...

  8. HDOJ 1905 Pseudoprime numbers(模运算)

    模运算..http://www.cnblogs.com/jojoke/articles/1003594.html Pseudoprime numbers Time Limit: 1000/1000 M ...

  9. Poj1995--Raising Modulo Numbers(快速幂)

    题目: http://poj.org/problem?id=1995 Input The input consists of Z assignments. The number of them is ...

最新文章

  1. [Go]结构体及其方法
  2. 环形buffer代码_为什么Buffer开发人员开源了他的代码
  3. 74.4k star 项目 YouTube-dl 重新上线,GitHub 强调将重点支持开源!
  4. 面试官:说说Java对象的四种引用方式
  5. 计算机视觉基础-图像处理 Task05 图像分割/二值化
  6. java动态变量名_Java||第一篇:了解Java并搭建环境
  7. linux 如何开放外网端口映射本地端口
  8. 【0门槛】PR稿的自我修养
  9. 端到端和非端到端的Embedding,以及embedding质量评估
  10. Win11 开机资源管理器频繁崩溃闪退怎么处理?
  11. 中国大学MOOC动物遗传学试题及答案
  12. vue中获取后一页面,前一页面的url
  13. matplotlib basemap 绘制多边形区域曲线
  14. web服务器部署证书
  15. 环境变量配置以mysql为例
  16. echart 柱状图 ---- 坐标轴、网格、柱体配置
  17. linux查看远程kafka安装目录,Linux系统中KafKa安装和使用方法
  18. 大数据对金融行业的影响,主要体现在哪几方面?
  19. windows注册表修改大全
  20. linux apache fcgi,Apache使用fcgi方式与PHP结合

热门文章

  1. [Java] 如何学Java
  2. NHibernate学习之基础配置
  3. 微软重拳出击:盗版 Windows 将无处遁形!
  4. 什么是PostgreSQL?跟MySQL、Oracle比强在哪?
  5. 年薪30k-50k、面试通过率90%,这个职位到底是在做什么?
  6. 【干货】全球大数据领域顶级开源工具汇总
  7. 魅族15无法连接计算机,还在为数据丢失而烦恼?魅族15告诉你什么叫做碎屏无忧...
  8. 低级程序员才喜欢写注释!
  9. Arthas - Java 线上问题定位处理的终极利器
  10. Jack Dorsey二度卸任推特CEO,原CTO接棒,立即生效!