Product of Three Numbers(CF-1294C)

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);
            } 
            else
                printf("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);
            } 
            else
                printf("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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值