Created
February 3, 2021 07:43
-
-
Save wataken44/6b262fcbd590adf5d65b7b3533dae433 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
import sys | |
def main(): | |
n = int(sys.argv[1]) | |
print(nth_prime(n)) | |
def nth_prime(n): | |
primes = [2] | |
k = 3 | |
while len(primes) < n: | |
is_prime = True | |
for p in primes: | |
if p * p > k: | |
break | |
if k % p == 0: | |
is_prime = False | |
break | |
if is_prime: | |
primes.append(k) | |
k += 2 | |
return primes[-1] | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment