The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
2 using namespace std;
3
4 long long GetFirstFactor(long long num)
5 {
6 long long root = sqrt((long double)num);
7 for(long long i=2; i<root; i++)
8 {
9 if(num % i == 0)
10 {
11 return i;
12 }
13 }
14
15 return num;
16 }
17
18 int main()
19 {
20 long long num = 600851475143;
21 long factor = 1;
22 while(num > 1)
23 {
24 long f = GetFirstFactor(num);
25 if(f > factor)
26 {
27 factor = f;
28 }
29
30 num = num / f;
31 }
32
33 cout << factor << endl;
34 cin.get();
35 }