Created
November 19, 2013 07:04
-
-
Save pmgupte/7541393 to your computer and use it in GitHub Desktop.
PHP solution to Project Euler problem # 10.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Problem 10: Summation of primes | |
* The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. | |
* Find the sum of all the primes below two million. | |
* | |
* Uses GMP - http://www.php.net/manual/en/book.gmp.php | |
*/ | |
for($prime=2, $sum=0; $prime < 2000000; $sum+=$prime, $prime=gmp_intval(gmp_nextprime($prime))); | |
echo "Sum of all prime numbers < 2 million is: $sum"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment