{"id":130,"date":"2014-04-24T14:58:08","date_gmt":"2014-04-24T21:58:08","guid":{"rendered":"http:\/\/willclausen.com\/?p=130"},"modified":"2014-04-24T14:58:08","modified_gmt":"2014-04-24T21:58:08","slug":"project-eurler-problem-10","status":"publish","type":"post","link":"https:\/\/willclausen.com\/?p=130","title":{"rendered":"Project Eurler Problem 10"},"content":{"rendered":"<p>Here&#8217;s the problem:<\/p>\n<p>Find the sum of all primes less than 2,000,000<\/p>\n<p>projecteuler.net\/problem=10<\/p>\n<p>My solution:<\/p>\n<pre class=\"brush: python; light: false; title: ; toolbar: true; notranslate\" title=\"\">\r\n\r\n# Author: Will Clausen\r\n#\r\n# Date: Jan 7, 2013\r\n#\r\n# This program will solve Problem 10 from Project Euler.\r\n# The code is basically the same as the code for Problem 7.\r\n\r\nimport math\r\n\r\n# Find the sum of all the primes below two million\r\ndef problem10():\r\n\t# 2 is the first prime number, so start there\r\n\tsum = 2\r\n\t\r\n\t# The next number to check is 3\r\n\tnum = 3\r\n\r\n\t# While there are still numbers to check\r\n\twhile num &lt; 2000000:\r\n\t\t# If the number is prime\r\n\t\tif isPrime(num):\r\n\t\t\t# Add the number to the total\r\n\t\t\tsum += num\r\n\t\t\r\n\t\t# And increment by 2 (since even numbers above 2 aren't prime)\r\n\t\tnum += 2\r\n\r\n\treturn sum\r\n\r\n# Simple function to determine if a number is prime. Not super fast,\r\n# but will work for this problem because the numbers aren't super huge.\r\ndef isPrime(Num):\r\n\t# Bound for divisors to check\r\n\tsqrtNum = int(math.sqrt(Num)) + 1\r\n\t\r\n\t# Only need to check if the number is divisible by odd numbers, so\r\n\t# do that in the range function\r\n\tfor x in range(3, sqrtNum, 2):\r\n\t\tif Num % x == 0:\r\n\t\t\treturn False\r\n\r\n\treturn True\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s the problem: Find the sum of all primes less than 2,000,000 projecteuler.net\/problem=10 My solution: # Author: Will Clausen # # Date: Jan 7, 2013 # # This program will solve Problem 10 from Project Euler. # The code is basically the same as the code for Problem 7. import math # Find the sum [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[32,31,42,33],"class_list":["post-130","post","type-post","status-publish","format-standard","hentry","category-project-euler","tag-primes","tag-problem-10","tag-project-euler","tag-sum"],"_links":{"self":[{"href":"https:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/posts\/130","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/willclausen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=130"}],"version-history":[{"count":1,"href":"https:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/posts\/130\/revisions"}],"predecessor-version":[{"id":131,"href":"https:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/posts\/130\/revisions\/131"}],"wp:attachment":[{"href":"https:\/\/willclausen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=130"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/willclausen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=130"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/willclausen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=130"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}