Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d689b4b

Browse files
SandersLinpoyea
authored andcommitted
Project Euler problem 7 solution 3 (TheAlgorithms#642)
1 parent 16e95a3 commit d689b4b

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎project_euler/problem_07/sol3.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'''
2+
By listing the first six prime numbers:
3+
2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.
4+
What is the Nth prime number?
5+
'''
6+
from __future__ import print_function
7+
# from Python.Math import PrimeCheck
8+
import math
9+
import itertools
10+
def primeCheck(number):
11+
if number % 2 == 0 and number > 2:
12+
return False
13+
return all(number % i for i in range(3, int(math.sqrt(number)) + 1, 2))
14+
15+
def prime_generator():
16+
num = 2
17+
while True:
18+
if primeCheck(num):
19+
yield num
20+
num+=1
21+
22+
def main():
23+
n = int(input('Enter The N\'th Prime Number You Want To Get: ')) # Ask For The N'th Prime Number Wanted
24+
print(next(itertools.islice(prime_generator(),n-1,n)))
25+
26+
27+
if __name__ == '__main__':
28+
main()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /