Sophie

Sophie

distrib > Mandriva > current > x86_64 > by-pkgid > 4eb48b954cf932f6d30c439317814ddd > files > 207

ruby1.9-doc-1.9.1.p378-3mdv2010.1.x86_64.rpm

# sieve of Eratosthenes
max = Integer(ARGV.shift || 100)
sieve = []
for i in 2 .. max
  sieve[i] = i
end

for i in 2 .. Math.sqrt(max)
  next unless sieve[i]
  (i*i).step(max, i) do |j|
    sieve[j] = nil
  end
end
puts sieve.compact.join(", ")