The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

Still, this is my second project; and my coding is at the very beginner level and there might be uncaught errors. My first approach was to decide whether the number that will be dividing 600851475143 is prime or not. So, I wrote a function which verifies the prime number by returning true. The following is the function:

/*function to check whether a number is a prime*/ bool isPrime(int input) { int count = 0; for (int loop = 1; loop < input; loop++) /*this loop will divide the number starting from 1 until it is divided by itself*/ { if (input%loop == 0) { count++; //This counts the number of time it is dividable with 0 remainder } } if (count == 1) //if the number has only one dividable value with 0 remainder then it's prime { return true; } else { return false; } }

Now, I have written the isPrime() function. Let’s move on to finding the prime factors of the number : 600851475143. Since the number is huge, I used the ‘long’ variable type. Again, this might not be the best solution as it’s going many cycles of loops; it will be greatly appreciated if I may have your idea in the comment section.

int main() { long number = 600851475143; //the input number int result = 0; for (int sequence = 1; sequence <= number; sequence++) //run the number till the input { if (isPrime(sequence)) //call the function and check the prime { if (number%sequence == 0) //prime number passes to here and divide the input { cout << "the result is " << sequence << endl; } } } cin.get(); //Just to stop the terminal from closing return 0; }

Ok, this is the result

the result is 71 the result is 839 the result is 1471 the result is 6857