mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-18 16:27:02 +00:00
Project Euler problem 7 solution 3 (#642)
This commit is contained in:
parent
16e95a3de5
commit
d689b4b083
28
project_euler/problem_07/sol3.py
Normal file
28
project_euler/problem_07/sol3.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
'''
|
||||
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 Nth prime number?
|
||||
'''
|
||||
from __future__ import print_function
|
||||
# from Python.Math import PrimeCheck
|
||||
import math
|
||||
import itertools
|
||||
def primeCheck(number):
|
||||
if number % 2 == 0 and number > 2:
|
||||
return False
|
||||
return all(number % i for i in range(3, int(math.sqrt(number)) + 1, 2))
|
||||
|
||||
def prime_generator():
|
||||
num = 2
|
||||
while True:
|
||||
if primeCheck(num):
|
||||
yield num
|
||||
num+=1
|
||||
|
||||
def main():
|
||||
n = int(input('Enter The N\'th Prime Number You Want To Get: ')) # Ask For The N'th Prime Number Wanted
|
||||
print(next(itertools.islice(prime_generator(),n-1,n)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Loading…
Reference in New Issue
Block a user