Created
April 20, 2013 11:45
-
-
Save hiroism007/5425721 to your computer and use it in GitHub Desktop.
エラトステネスのふるい
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
puts "素数リストを作成します。数えたい最大の数を入れてください\n" | |
max_number = gets.to_i | |
primes = {} | |
for i in 2..max_number do primes[i] =true end | |
for i in 2..max_number do | |
(2*i).step(max_number,i){|n| primes[n] = false } if primes[i]==true | |
end | |
p primes.delete_if{|k,v| v == false}.keys |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment