I am trying to find the largest prime factor of 600851475143 and here is the code:
function find($x){
$lpf = 2;
while($x > $lpf){
if($x%$lpf == 0){
$x = $x/$lpf;
$lpf = 2;
}else{
$lpf +=1;
}
}
echo $lpf;
}
find(600851475143);
It would echo just 2 but the algorithm is working fine with smaller numbers. What is the problem?