Builidng Better Solutions For Web Development Recent WorkHow We Work
ProjectEuler.net
P1 | P2 | P3 | P4 | P5 | P6 | P7 | P8 | P9 | P10 | P22

Project Euler.net Answers

Problem 3

Solved on 2/29/2008

The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? Note: This problem has been changed recently, please check that you are using the right number.

$number = 600851475143;
for($ic = 2; $ic <= sqrt($number); $ic++){
$thisint = $number / $ic;
$string = strval($thisint);
$isint = strpos($string, '.');
if($isint === FALSE){
$bn = $number / $ic;
if($this->isPrime($bn)){
$answer = $bn;
$ic = $number;
}else if($this->isPrime($ic)){
$answer = $ic;
}
}
}


public function isPrime($val){
if(($val % 2 ) == 0) return FALSE;
for($c = 3; $c <= sqrt($val); $c+=2) {
if(($val % $c ) == 0) return FALSE;
}
return TRUE;
}
$answer = 6,857

Latest News
Feb. 11, 2008
Wells Ideas Inc. launches their redesigned site.

The site is built on a symfony platform and utilizes client information from their project management site.
Quote Of The Day
"The greatest challenge to any thinker is stating the problem in a way that will allow a solution."
- Bertrand Russell