-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1294C_Product_of_Three_Numbers.cpp
66 lines (63 loc) · 1.14 KB
/
1294C_Product_of_Three_Numbers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
void solve()
{
int n;
cin >> n;
vector<int> v;
for (int i = 2; i <= sqrt(n); i++)
{
if (n % i == 0)
{
if (n / i == i)
{
if (find(v.begin(), v.end(), i) == v.end())
{
v.push_back(i);
}
}
else
{
if (find(v.begin(), v.end(), i) == v.end())
{
v.push_back(i);
}
if (find(v.begin(), v.end(), n / i) == v.end())
{
v.push_back(n / i);
}
}
}
}
sort(v.begin(), v.end());
for (int i = 0; i + 2 < v.size(); i++)
{
for (int j = i + 1; j + 1 < v.size(); j++)
{
for (int k = i + 2; k < v.size(); k++)
{
if (v[i] * v[j] * v[k] == n)
{
cout << "YES" << endl;
cout << v[i] << " " << v[j] << " " << v[k] << endl;
return;
}
}
}
}
cout << "NO" << endl;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}