Question Number
3
Project Euler Question

The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?

Solution Found
True

File Status: Solution File found. Code from the function code_solution_3 will be used

Solution: 71 * 839 * 1471 * 6857

Solution Code:

      <?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);
  }