MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / PrimeFactor

Function PrimeFactor

CPP/Maths/primeFactor.cpp:4–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2using namespace std;
3
4void PrimeFactor(int n)
5{
6 if (n == 1)
7 return;
8
9 int i = 2;
10 while (n % i == 0)
11 {
12 cout << i << ' ';
13 n = n / i;
14 }
15
16 i = 3;
17 while (n % i == 0)
18 {
19 cout << i << ' ';
20 n = n / i;
21 }
22
23 for (int i = 5; i * i <= n; i = i + 6)
24 {
25 while (n % i == 0)
26 {
27 cout << i << ' ';
28 n = n / i;
29 }
30 while (n % (i + 2) == 0)
31 {
32 cout << i + 2 << ' ';
33 n = n / (i + 2);
34 }
35 }
36 if (n > 3)
37 cout << n << " ";
38}
39
40int main()
41{

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected