#import <cmath>
#import <iostream>
using namespace std;
int main {
int a;
for(int x = 600851475142; x>cmath::sqrt(600851475143); x--) {
if (600851475143%x==0) { //is it a factor of 600851475143?
if p(x) { //is it also a prime?
cout << x;
return 0;
}
}
}
}
bool p(int n) {
for(int x = n; x<cmath::sqrt(n)+1; x++) {
if (n%x==0) {
return false;
}
}
return true;
}
Here is my code for project euler #3 (http://projecteuler.net/problem=3). I am relatively new to C++.
Basically my approach was to count down from 600851475143, test if the number was a factor of 600851475143 and then see if it was prime. If it was then return the number and exit. However, when I compile my code I get the error:
error: function definition does not declare parameters
In function 'bool p(int)':
error: 'cmath' has not been declared
Any help would be appreciated