Skip to content

Instantly share code, notes, and snippets.

@lune-sta
Created August 13, 2012 21:18
Show Gist options
  • Save lune-sta/3344173 to your computer and use it in GitHub Desktop.
Save lune-sta/3344173 to your computer and use it in GitHub Desktop.
Project Euler 23
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