Let take the number be 600851475143, so to find the largest prime factor run the following code
Result : 6857
<?php
$max = 600851475143;
$l_num = 0;
for ($j = floor(sqrt($max)) / 2; $j >= 2; $j--)
{
if (!($j % 2)) {
continue;
}
$d = 3;
$x = sqrt($j);
while (($j % $d) && $d < $x) {
$d += 2;
}
if (((!($j % $d) && $j != $d) * 1) == 0)
{
if (!($max % $j))
{
$l_num = $j;
break;
}
}
}
echo $l_num;
?>