Created
August 13, 2012 21:18
-
-
Save lune-sta/3344173 to your computer and use it in GitHub Desktop.
Project Euler 23
This file contains 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
require 'prime' | |
m = 28123 | |
sum = 0 | |
adn = Array.new() | |
flag = Array.new(m+1){false} | |
2.upto(m) do |i| | |
a = 1 | |
i.prime_division.each do |j| | |
b = 0 | |
(j[1]+1).times do |k| | |
b += j[0]**k | |
end | |
a *= b | |
end | |
a -= i | |
adn.push(i) if a > i | |
end | |
adn.each do |i| | |
adn.each do |j| | |
flag[i+j] = true if i + j <= m | |
end | |
end | |
m.times do |i| | |
sum += i if !flag[i] | |
end | |
puts sum # 4179871 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment