.
This commit is contained in:
parent
7b6f0aeedb
commit
a2a0d9a1a4
24
euler7.php
Normal file
24
euler7.php
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
/*
|
||||||
|
* Gnieark's anwser to euler problem 6
|
||||||
|
* https://projecteuler.net/problem=6
|
||||||
|
*/
|
||||||
|
|
||||||
|
$primesNumbers=array(2);//ommit 1
|
||||||
|
$i=3;
|
||||||
|
while(count($primesNumbers)<10001){
|
||||||
|
$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;
|
||||||
|
echo (count($primesNumbers))." ".$i."\n";
|
||||||
|
}
|
||||||
|
$i=$i+2;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user