Skip to content

Instantly share code, notes, and snippets.

@fsword
Created June 8, 2012 16:51
Show Gist options
  • Save fsword/2896832 to your computer and use it in GitHub Desktop.
Save fsword/2896832 to your computer and use it in GitHub Desktop.
求N以内的素数
def prime n
list = (2..n).to_a
(2...(n ** (0.5)).floor).each do |i|
list.delete_if{|e| e > i && e % i == 0}
end
list
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment