-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProduct of Three Numbers.cpp
96 lines (90 loc) · 2.66 KB
/
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// https://codeforces.com/contest/1294/problem/C
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ll long long
#define pll pair<long, long>
#define vll vector<long long>
#define inf 1e18
#define range(a,b) substr(a,b-a+1)
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
int main()
{
FIO;
#ifndef ONLINE_JUDGE
//remove this piece of code when this has to be submitted in kickstart
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
//freopen is used to associate a file with stdin or stdout stream in C++
#endif
ll t;
cin >> t;
while (t--) {
ll n;
cin >> n;
if (n % 2 == 0) {
ll co = 1;
vll arr{2};
n /= 2;
for (ll i = 3; i < sqrt(n) * log(n); i++) {
if (n % i == 0) {
arr.pb(i);
n /= i;
co++;
break;
}
if ((n / i) < 3)
break;
}
if (co == 2 && n > arr[1]) {
cout << "YES\n";
for (ll i = 0; i < 2; i++)
cout << arr[i] << " ";
cout << n;
cout << "\n";
}
else
cout << "NO\n";
}
else {
ll co = 0;
vll arr;
for (ll i = 3; i < sqrt(n) * log(n); i += 2) {
if (n % i == 0) {
co++;
arr.pb(i);
n /= i;
break;
}
}
if (arr.size() > 0) {
for (ll i = arr[0] + 2; i < sqrt(n) * log(n); i += 2) {
if (n % i == 0) {
co++;
arr.pb(i);
n /= i;
break;
}
if ((n / i) < arr[0] + 2)
break;
}
if (arr.size() > 1) {
if (n > arr[1]) {
cout << "YES\n";
cout << arr[0] << " " << arr[1] << " " << n <<"\n";
}
else
cout << "NO\n";
}
else
cout << "NO\n";
}
else
cout << "NO\n";
}
}
return 0;
}