Product of Three Numbers(CF-1294C)

news/2025/2/12 7:51:01/

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

 


http://www.ppmy.cn/news/536257.html

相关文章

CF1042C Array Product

原题链接&#xff1a;http://codeforces.com/contest/1042/problem/C Array Product You are given an array a a a consisting of n n n integers. You can perform the following operations with it: Choose some positions i i i and j ( 1 ≤ i , j ≤ n , i ≠ j )…

Cyc简介

Cyc中的概念被称为“常量(constants)”。常量以"#$"开头并区分大小写。常量主要分为以下几类&#xff1a; 个体&#xff0c;即individuals&#xff1a;例如 #$BillClinton 又如 #$France。 集合&#xff0c;即Collections&#xff1a;例如 #$Tree-ThePlant (包含所有…

C1-02

任务一&#xff1a; 网页返回信息&#xff1a; Unicode转码: 填入字段返回&#xff1a; 任务二&#xff1a;....... 拓展&#xff1a; 使用子网掩码将一组C类IP地址&#xff08;范围为192.168.99.0~192.168.99.255&#xff09;划分成四个子网 *掌握IP组网技术&#xff0c;理…

C12

输入一个三位的正整数&#xff0c;判断该数是否为水仙花数&#xff08;水仙花数指的是一个三位数&#xff0c;其各位数字的立方和等于该数本身。例如&#xff1a;153是一个水仙花数&#xff0c;因为153111555333&#xff09;。 #include<stdio.h> void main() {int a, b…

C1_2

文章目录 1、网络数据抓包2、对之前未学概念的总结1.路由消息2.数据包3.域名4.子网5子网划分6.补充 3、自测1.四种常用网络拓布结构2.OSI应用层支持那些协议3.DNS的作用4.ARP和RARP的作用 1、网络数据抓包 1.在官网下载fiddler经典版 2.打开fidder&#xff0c;然后访问⽹址&am…

C1/C1/C2 カバレッジについて

C1/C1/C2 カバレッジについて ■いつも忘れてしまうカバレッジの違いについて C0/C1/C2 検査網羅率(テストカバレージ) ── どれだけテストしたか、の指標。 例: void function(...) {if ( 条件A || 条件B ) {処理1} else {処理2}if ( 条件C ) {処理3} else {処理4} }C0: 命…

CSS12

一、盒子圆角和盒子阴影 1、盒子圆角 可以使盒子的角变为圆角&#xff0c;与PS中的圆角一致&#xff1b; border-radius&#xff1a;50% 可以简单地理解为把圆角值拉满 border-radius:100px; border-radius:10px 20px 30px 40px; 左上 右上 右下 …

gtk_table_attch与gtk_grid_attach的区别

gtk_table_attch与gtk_grid_attach的区别 button gtk_button_new_with_label (“Short fat button”); gtk_table_attach (GTK_TABLE (table), button, 0, 2, 3, 4, xoptions, yoptions, 0, 0); 0—2–3—4 左 右 上 下 /* 横线从左边的0移到右边的2&#xff0c;竖线从上边的…