{"id":518,"date":"2012-08-02T15:35:48","date_gmt":"2012-08-02T19:35:48","guid":{"rendered":"http:\/\/www.joshho.com\/blog\/?p=518"},"modified":"2012-09-07T16:13:16","modified_gmt":"2012-09-07T20:13:16","slug":"project-euler-problem-30","status":"publish","type":"post","link":"https:\/\/www.joshho.com\/blog\/2012\/08\/02\/project-euler-problem-30\/","title":{"rendered":"Project Euler &#8211; Problem 30"},"content":{"rendered":"<p>Problem 30: Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.<br \/>\n<!--more--><\/p>\n<p><code><\/p>\n<pre lang='java'>\r\n\r\nclass runner\r\n{\t\r\n\tpublic static void main (String[] args) throws java.lang.Exception\r\n\t{\r\n\t\tlong time = System.currentTimeMillis();\r\n\t\t\r\n\t\tint[] storage = new int[10]; \r\n\t\t\/\/populate hashmap\r\n\t\tfor(int i=1; i<10; i++){\r\n\t\t\tstorage[i] = (int) Math.pow(i,5);\r\n\t\t}\r\n\t\t\r\n\t\tint match_sum = 0;\r\n\t\tint i=2;\r\n\t\twhile(true){\r\n\t\t\tint cur = i; int sum = 0;\r\n\t\t\twhile(cur>0){\r\n\t\t\t\tint div = cur % 10;\r\n\t\t\t\tsum += storage[div];\r\n\t\t\t\tcur \/= 10;\r\n\t\t\t}\r\n\t\t\t\/\/System.out.println(i + \" sum:\" +sum);\r\n\t\t\tif(i == sum){\r\n\t\t\t\tmatch_sum+=i;\r\n\t\t\t}else if(i > 999999){\/\/limit.. 999999 = 354294\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t\ti++;\r\n\t\t}\r\n\t\t\r\n\t\tSystem.out.println(match_sum);\r\n\t\tSystem.out.println(\"time:\"+(System.currentTimeMillis()-time));\r\n\t}\r\n}\r\n<\/pre>\n<p><\/code><br \/>\nNote: Limit is 999999 as 9^5*6 = 354294; actual limit is left for reader to solve.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem 30: Find the sum of all the numbers that can be written as the sum of fifth powers of their digits.<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[56],"tags":[],"_links":{"self":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/posts\/518"}],"collection":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/comments?post=518"}],"version-history":[{"count":0,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/posts\/518\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/media?parent=518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/categories?post=518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.joshho.com\/blog\/wp-json\/wp\/v2\/tags?post=518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}