-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprime.cpp
More file actions
99 lines (64 loc) · 1.58 KB
/
prime.cpp
File metadata and controls
99 lines (64 loc) · 1.58 KB
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
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
//input.txt
freopen("input1.txt", "r", stdin);
//output.txt
freopen("output1.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
// prime numbers -> 2 is the only even prime number
// prime number can be written as 6b+1 or 6n-1 , n is the natural number
// , except 2 and 3
/*
goldbach conjection -> every even int greater than 2 can be expressed
as the sum of two prime numbers
ex. 10 = 3 + 7
2 and 3 are only prime that are consecutive.
wilson's theorem -> (p-1)! = (p-1) % p
ex: p = 5 (prime number)
(5-1)! = (4) % 5 = 4
// check if the number is prime or not
// it must be divisible by 1 and itself and must have exactly 2 factors
// tc -> O(N)
//better optimization -> O(sqr(N) * logN) -> use sqt(n)
// print the sum of factor -> if(n(i) != i) sum += (n/i)
// codeforces - 1294c
*/
int t;
cin >> t;
while (t--)
{
int n;
cin >> n;
int a = n, b = n, c = n;
for (int i = 2; i * i <= n; i++)
{
if (n % i == 0)
{
a = i;
break;
}
}
n = n / a;
for (int i = 2; i * i <= n; i++)
{
if (n % i == 0 && i != a)
{
b = min(b, i);
}
}
c = n / b;
if (a != b && b != c && c > 1)
{
cout << "YES" << endl;
cout << a << " " << b << " " << c << " " << endl;
}
else
{
cout << "NO" << endl;
}
}
}