/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php function isPrime($num) { if ($num == 2 || $num == 3) { return 1; } if (!($num%2) || $num<1) { return 0; } for ($n = 3; $n <= $num/2; $n += 2) { if (!($num%$n)) { return 0; } } return 1; } for ($i = 2; $i <= N; $i++) { if (isPrime($i)) { $sum += $i; } } echo $sum;