Skip to content

Instantly share code, notes, and snippets.

@Manume
Last active August 29, 2015 14:02
Show Gist options
  • Save Manume/584887d293c4a707dd61 to your computer and use it in GitHub Desktop.
Save Manume/584887d293c4a707dd61 to your computer and use it in GitHub Desktop.
program to Find the sum of all the primes below two million.
class Prime
require'mathn'
max = 2_000_000
sum = 0
Prime.each { |x|
break if x >= max;
sum+=x
}
obj=Prime.new
puts" the sum of all the primes below two million is #{sum}"
end
=begin
output:
the sum of all the primes below two million is 142913828922
=end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment