-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject3.cpp
More file actions
50 lines (40 loc) · 997 Bytes
/
project3.cpp
File metadata and controls
50 lines (40 loc) · 997 Bytes
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
/*
The prime factors of 13195 are 5, 7, 13, and 29.
What is the largest prime factor of the number 600851475143?
*/
/*
Psuedocode
Outer loop while a possible factor is less than the number being passed
If the input number divided by current possible factors remainder is 0
output that number, it is a factor.
divide the input number by current factor
Else
incriment the possible factor by 1
After all division if the input number is greater than 1, output it as it is also a factor
*/
#include <iostream>
void primeFactors(long long n);
int main()
{
primeFactors(600851475143);
return 0;
}
void primeFactors(long long n)
{
long long z = 2;
while(z * z <= n)
{
if(n % z == 0)
{
std::cout << z << std::endl;
n /= z;
}
else
{
z++;
}
}
if(n > 1) {
std::cout << n << std::endl;
}
}