2015-11-14 23:01:47 +01:00
|
|
|
<?php
|
|
|
|
/*
|
2015-11-15 11:18:16 +01:00
|
|
|
* Gnieark's anwser to euler problem 10
|
|
|
|
* https://projecteuler.net/problem=10
|
2015-11-14 23:01:47 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
$primesNumbers=array(2);//ommit 1
|
|
|
|
$i=3;
|
2015-11-15 11:18:16 +01:00
|
|
|
$sum=2;
|
|
|
|
while($i<2000000){
|
2015-11-14 23:01:47 +01:00
|
|
|
$isPrimaryNumber=true;
|
|
|
|
$index=0;
|
|
|
|
while(($primesNumbers[$index]<=sqrt($i)) && $index < count($primesNumbers)){
|
|
|
|
if(fmod($i,$primesNumbers[$index])==0){
|
|
|
|
$isPrimaryNumber=false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
$index++;
|
|
|
|
}
|
|
|
|
if($isPrimaryNumber){
|
|
|
|
$primesNumbers[]=$i;
|
2015-11-15 11:18:16 +01:00
|
|
|
$sum+=$i;
|
2015-11-14 23:01:47 +01:00
|
|
|
}
|
|
|
|
$i=$i+2;
|
2015-11-15 11:18:16 +01:00
|
|
|
}
|
|
|
|
echo $sum;
|