-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem-007.py
More file actions
51 lines (40 loc) · 948 Bytes
/
problem-007.py
File metadata and controls
51 lines (40 loc) · 948 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""
Problem 7 - 10001st Prime
By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see
that the 6th prime is 13.
What is the 10,001st prime number?
"""
def is_prime(n: int) -> bool:
"""
Parameters
n (int): number to check primality
Returns
boolean
"""
if n < 2:
return False
elif n == 2:
return True
else:
for i in range(2, round(n ** 0.5) + 1):
if n % i == 0:
return False
return True
def nth_prime(n: int) -> int:
"""
Parameters
n (int): prime number of interest
Returns
nth_prime (int): nth prime number
"""
curr_n = 2
count = 0
while True:
if is_prime(curr_n):
count += 1
if count == n:
break
curr_n += 1
return curr_n
if __name__ == "__main__":
print("The 10,001st prime number is: " + str(nth_prime(10001)))