Overview

 

Question

The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.

Find the sum of all the primes below two million.

click for answer

142913828922

Solutions

 

Ruby

 primesUnder2mm.rb https://raw.github.com/addamh/euler/master/010/primesUnder2mm.rb download
#!/usr/bin/env ruby

require 'mathn'
puts Prime.take_while{ |n| n < 2000000 }.inject(0){|sum,item| sum + item}
$ time ruby primesUnder2mm.rb
real	0m13.686s
user	0m13.627s
sys	0m0.053s