Skip to content

Instantly share code, notes, and snippets.

@masahixixi
Created October 30, 2012 07:20
Show Gist options
  • Save masahixixi/3978766 to your computer and use it in GitHub Desktop.
Save masahixixi/3978766 to your computer and use it in GitHub Desktop.
ProjectEuler #10 Sieve of Eratosthenes
require "mathn"
num = 2000000
num_list = (2..num).to_a
pri_list = Array.new
sum_list = Array.new
tmp = 2
sum = 0
while tmp <= Math.sqrt(num)
pri_list << tmp
num_list.reject! do |e|
e % tmp == 0
end
tmp = num_list.min
end
sum_list = pri_list + num_list
sum_list.each do |i|
sum += i
end
p sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment