I'm a little new to programming, right now trying to find the largest prime factor of 600851475143, for Project Euler. My code won't compile when I actually try and do the Fermat Primality test.
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int main () {
long long int num = 600851475143;
long long int factor = num / 2;
for (long long factor; factor > 0; factor--) {
//Use Fermat primality test.
if (num % factor == 0) {
long long int testNum1 = rand() % 50 + 1;
long long int testNum2 = rand() % 50 + 1;
long long int test1 = (pow(testNum1, factor - 1) % factor);
long long int test2 = (pow(testNum2, factor - 1) % factor);
if (test1 == 1 && test2 == 1){
cout << "The greatest prime factor is: " << factor;
break;
}
}
}
return 0;
}