-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem3.cpp
48 lines (45 loc) · 1.17 KB
/
Problem3.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
#include<iostream>
using namespace std;
unsigned long long int return_largest_factor(unsigned long long int num_to_factor)
{
unsigned long long int largest_factor;
// ISSUE: is i<num_to_factor or i<=num_to_factor
for (unsigned long long int i=3; i<num_to_factor; i+=2)
{
// cout<<"Loop value is: "<<i;
if (num_to_factor%i == 0)
{
// cout<<"Loop value is: "<<i;
if(i<=num_to_factor/i)
{
largest_factor = num_to_factor/i;
}
else
{
largest_factor = i;
}
break;
}
}
return largest_factor;
}
int main()
{
unsigned long long int num_to_factor = 600851475143, largest_factor;
//unsigned long long int num_to_factor = 8462696833;
int prime_factor=0;
while(prime_factor !=1)
{
largest_factor = return_largest_factor(num_to_factor);
if (largest_factor<num_to_factor)
{
num_to_factor = largest_factor;
}
else
{
cout << "The largest factor is: "<< largest_factor << "\n";
prime_factor=1;
}
}
return 0;
}