【解题】Product of Three Numbers

博客详细介绍了如何解决codeforces上的1294C问题,即寻找三个不同的整数a, b, c,使得它们的乘积等于给定的整数n。当能找到符合条件的a, b, c时输出'YES'和一个可能的组合,否则输出'NO'。博主提出了利用质因数分解和集合来确定不同数值的方法,并给出了样例输入和输出,以及代码实现。" 102546514,1362984,IPGuard流量控制策略实践与应用,"['网络管理', '流量监控', 'IP-guard', '安全策略']
摘要由CSDN通过智能技术生成

题目链接:codeforces 1294C
题目:
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.
输入
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≤10^9).
输出
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.
题目大意:在T个样例内,每个样例给定一个数字,如果能找到找到一组都大于1且不同的整数abc,使得a* b *c=n 输出YES 并给出对应的值 否则输出NO

样例
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823
思路:分解质因数的想法,并用集合set来得到不同的数字。判断集合中是否有三个值,若有则YES,无则NO
代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
set<
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值