Created
September 17, 2012 14:36
-
-
Save masahixixi/3737754 to your computer and use it in GitHub Desktop.
ProjectEuler #7
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
require "prime" | |
pri = [] | |
num = 2 | |
while pri.size < 10001 | |
if Prime.instance.prime?(num) == true | |
pri << num | |
end | |
num += 1 | |
end | |
p pri.last |
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
require "prime" | |
num = 0 | |
count = 0 | |
while count <= 10000 | |
num += 1 | |
count += 1 if num.prime? | |
end | |
p num |
if Prime.instance.prime?(num) == true
は、 if num.prime?
でOKやね
改良してみました。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
10001番目の素数さえわかれば良いので、1〜10000番目の素数を配列に入れなくても、今素数をいくつ見つけたかをカウントすれば良い