I have no idea why g++ doesn't like my code. It ran fine in java. Any insights would be greatly appreciated.
#include<iostream>
using namespace std;
bool isPrime(long number);
int main(){
const long number = 600851475143;
long max = 0;
for(long i= 0; i*i <= number; i++)
if(number % i == 0 && isPrime(i))
max = i;
cout<< max << endl;
return 0;
}
bool isPrime(long number){
if(number <= 1) return false;
if(number == 2) return true;
if(number % 2 == 0) return false;
for(long i= 3; i*i <= number; i+=2)
if(number % i == 0)
return false;
return true;
}
See Question&Answers more detail:os