Last active
August 29, 2015 14:02
-
-
Save Manume/584887d293c4a707dd61 to your computer and use it in GitHub Desktop.
program to Find the sum of all the primes below two million.
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
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