title: Calculating prime factors for Project Euler
body: <p>I need to find the greatest prime factor of a large number: up to 12 places (xxx,xxx,xxx,xxx).  I have solved the problem, and the code works for small numbers (up to 6 places); however, the code won't run fast enough to not trigger a timeout on my server for something in the 100 billions.</p>
  
  <p><strong>I found a solution, thanks to all.</strong></p>
  
  <p>Code:</p>
  
  <pre><code>&lt;?php   
      set_time_limit(300);
  
      function is_prime($number) {
          $sqrtn = intval(sqrt($number));
          //won't work for 0-2
              for($i=3; $i&lt;=$sqrtn; $i+=2) {
                  if($number%$i == 0) {
                      return false;
                  }
              }
          return true;
      }   
  
      $initial = 600851475143;
      $prime_factors = array();
  
      for($i=3; $i&lt;=9999; $i++) {
          $remainder = fmod($initial, $i);
          if($remainder == 0) {
              if(is_prime($i)) {
                  $prime_factors[] = $i;
              }
          }
      }
  
      //print_r($prime_factors);
      echo "\n\n";
      echo "&lt;b&gt;Answer: &lt;/b&gt;". max($prime_factors);    
  ?&gt;
  </code></pre>
  
  <p>The test number in this case is 600851475143.</p>