Project Euler Question
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
<?php
function code_solution_3() {
$prime_factors = [];
$num_to_check = 600851475143;
$current_value = $num_to_check;
$max_check = sqrt($num_to_check);
for($i = 2; $i < $max_check; $i++) {
if(is_prime($i)) {
$is_factor = $current_value % $i == 0;
if($is_factor){
$prime_factors[] = $i;
$current_value = $current_value / $i;
}
}
}
return implode(" * ", $prime_factors);
}