Returns the n-th prime number. >>> solution(6) 13 >>> solution(1) 2 >>> solution(3) 5 >>> solution(20) 71 >>> solution(50) 229 >>> solution(100) 541
(nth: int = 10001)
| 50 | |
| 51 | |
| 52 | def solution(nth: int = 10001) -> int: |
| 53 | """ |
| 54 | Returns the n-th prime number. |
| 55 | |
| 56 | >>> solution(6) |
| 57 | 13 |
| 58 | >>> solution(1) |
| 59 | 2 |
| 60 | >>> solution(3) |
| 61 | 5 |
| 62 | >>> solution(20) |
| 63 | 71 |
| 64 | >>> solution(50) |
| 65 | 229 |
| 66 | >>> solution(100) |
| 67 | 541 |
| 68 | """ |
| 69 | |
| 70 | count = 0 |
| 71 | number = 1 |
| 72 | while count != nth and number < 3: |
| 73 | number += 1 |
| 74 | if is_prime(number): |
| 75 | count += 1 |
| 76 | while count != nth: |
| 77 | number += 2 |
| 78 | if is_prime(number): |
| 79 | count += 1 |
| 80 | return number |
| 81 | |
| 82 | |
| 83 | if __name__ == "__main__": |