Skip to content

Instantly share code, notes, and snippets.

@lune-sta
Created August 12, 2012 07:41
Show Gist options
  • Save lune-sta/3330516 to your computer and use it in GitHub Desktop.
Save lune-sta/3330516 to your computer and use it in GitHub Desktop.
Project Euler 21
require 'prime'
arr = Array.new(10001){1}
sum = 0
2.upto(10000) do |i|
i.prime_division.each do |j|
a = 0
(j[1]+1).times do |k|
a += j[0]**k
end
arr[i] *= a
end
arr[i] -= i
end
1.upto(10000) do |i|
(i+1).upto(10000) do |j|
sum += i + j if arr[i] == j && arr[j] == i
end
end
puts sum # 31626
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment