.
This commit is contained in:
parent
8822f3cc79
commit
867e1507c9
26
euler10.php
Normal file
26
euler10.php
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Gnieark's anwser to euler problem 10
|
||||||
|
* https://projecteuler.net/problem=10
|
||||||
|
*/
|
||||||
|
|
||||||
|
$primesNumbers=array(2);//ommit 1
|
||||||
|
$i=3;
|
||||||
|
$sum=2;
|
||||||
|
while($i<2000000){
|
||||||
|
$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;
|
||||||
|
$sum+=$i;
|
||||||
|
}
|
||||||
|
$i=$i+2;
|
||||||
|
}
|
||||||
|
echo $sum;
|
Loading…
Reference in New Issue
Block a user