So, I wrote php program to find the largest prime factor with php and I think it is quite optimal, because it loads quite fast. But there is a problem, it doesn't count very big numbers's prime factors. Here is a program:
function is_even($s) {
$sk_sum = 0;
for($i = 1; $i <= $s; $i++) {
if($s % $i == 0) { $sk_sum++; }
}
if($sk_sum == 2) {
return true;
}
}
$x = 600851475143; $i = 2; //x is number
while($i <= $x) {
if($x % $i == 0) {
if(is_even($i)) {
$sk = $i; $x = $x / $i;
}
}
$i++;
}
echo $sk;