Prime Formula
by michiganfootball20
HTML
<html>
<head>
<title>Online PHP Script Execution</title>
</head>
<body>
<?php
function buildPrimeArray($n){
$ints = array();
$primes = array(2);
for($i = 1; $i < $n; $i++) $ints[$i] = true;
//Loop through possible i values
for($i = 1; $i < (sqrt(2*$n+1)-1)/2; $i++){
//Loop through possible j values
for($j = $i; $j < (($n-$i)/(2*$i+1)); $j++){
$ints[intVal($i+$j+2*($i*$j))] = false;
}
}
foreach($ints as $val => $bool) {
if($bool) $primes[] = 2*$val+1;
}
return $primes;
}
$primes = buildPrimeArray((2000000-1)/2);
$count = 0;
for($i = 0; $i < count($primes); $i++) $count += $primes[$i];
echo $count;
?>
</body>
</html>