<?
/******************************************************************
* ProjectEuler.net * Problem 7 * 2010-05-31 * Martin Caine *
******************************************************************/
// create an array to store the primes
$primes = array();
$primes[] = 2;
// count the primes
$i = 1;
$n = 2;
// break when we get to 10001
while( $i < 10001 )
{
$n++;
$isPrime = true;
foreach( $primes as $prime )
{
if( ($n/$prime) == (int)($n/$prime) )
{
$isPrime = false;
break;
}
}
if( $isPrime )
{
$primes[] = $n;
$i++;
}
}
echo $primes[10000];
?>
If you found this post helpful please leave a comment below: