{"id":97,"date":"2013-01-17T21:47:48","date_gmt":"2013-01-18T05:47:48","guid":{"rendered":"http:\/\/willclausen.com\/?p=97"},"modified":"2013-01-17T21:48:12","modified_gmt":"2013-01-18T05:48:12","slug":"solution-project-euler-problem-5","status":"publish","type":"post","link":"http:\/\/willclausen.com\/?p=97","title":{"rendered":"Solution: Project Euler Problem 5"},"content":{"rendered":"<p>The Problem:<\/p>\n<p style=\"padding-left: 30px;\">What is the smallest positive number that is\u00a0<dfn title=\"divisible with no remainder\">evenly divisible<\/dfn>\u00a0by all of the numbers from 1 to 20<\/p>\n<p>My Solution (in C++):<\/p>\n<pre class=\"brush: cpp; 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 5 from Project Euler.\r\n\/\/ I had previously written a solution to this problem in\r\n\/\/ python, but it is not fast enough (primarily becuase I\r\n\/\/ did not think cleverly about the problem).\r\n\r\n#include &lt;iostream&gt;\r\n#include &lt;cstddef&gt;\r\n\r\nusing namespace std;\r\n\r\nsize_t gcd(size_t a, size_t b);\r\n\r\nsize_t lcm(size_t a, size_t b);\r\n\r\nsize_t problem5(size_t maxDivisor)\r\n{\r\n\tsize_t LCM = 1;\r\n\r\n\tfor (size_t i = 1; i &lt;= maxDivisor; ++i) {\r\n\t\tLCM = lcm(LCM, i);\r\n\t}\r\n\r\n\treturn LCM;\r\n}\r\n\r\nsize_t gcd(size_t a, size_t b)\r\n{\r\n\tif (b == 0)\r\n\t\treturn a;\r\n\r\n\tif (b &lt;= a)\r\n\t\treturn gcd(b, a%b);\r\n\telse\r\n\t\treturn gcd(b, a);\r\n}\r\n\r\nsize_t lcm(size_t a, size_t b)\r\n{\r\n\treturn (a*b\/gcd(a,b));\r\n}\r\n\r\n\/\/ Output with maxDivisor 20: 232792560\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The Problem: What is the smallest positive number that is\u00a0evenly divisible\u00a0by all of the numbers from 1 to 20 My Solution (in C++): \/\/ Author: Will Clausen \/\/ \/\/ Date: Jan 7, 2013 \/\/ \/\/ This program will solve Problem 5 from Project Euler. \/\/ I had previously written a solution to this problem in [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[9,24,19],"class_list":["post-97","post","type-post","status-publish","format-standard","hentry","category-project-euler-solutions","tag-january2013","tag-project-euler-problem-5","tag-project-euler-solution"],"_links":{"self":[{"href":"http:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/posts\/97","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/willclausen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=97"}],"version-history":[{"count":3,"href":"http:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/posts\/97\/revisions"}],"predecessor-version":[{"id":100,"href":"http:\/\/willclausen.com\/index.php?rest_route=\/wp\/v2\/posts\/97\/revisions\/100"}],"wp:attachment":[{"href":"http:\/\/willclausen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=97"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/willclausen.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=97"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/willclausen.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}