All pastes #941615 Raw Edit

Untitled

public ruby v1 · immutable
·published 2008-03-13 20:39 UTC
rendered paste body
#!/usr/bin/ruby#PROBLEM:#The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.#Find the sum of all the primes below two million.#SOLUTION#Summing primes up to and with:n=2*10**6#Initializing. 2 is not recognized as prime using the method below and hence sum=2.number=2sum=2while number < n+1 do  k=1  i=2  while i < Math.sqrt(number)+1 and k == 1 do    k=0 if number % i == 0 end    i= i+1  end  sum = sum + k*number  number = number+1endputs sum