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 10

Solved on 2/26/2008

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

Note: This problem has been changed recently, please check that you are using the right parameters.



0

$number = (int)$this->getRequestParameter('number');
$sum = 5;
if($number <= 2000000 && $number >= 3){
for($ic = 6; $ic <= $number+1; $ic+=6){
if($this->isPrime($ic-1)) $sum+= $ic-1;
if($ic <= $number && $this->isPrime($ic+1)) $sum+= $ic+1;
}
}


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

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