-
Notifications
You must be signed in to change notification settings - Fork 0
/
project_euler_Q7.py
55 lines (41 loc) · 1.32 KB
/
project_euler_Q7.py
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
52
53
54
55
#
# Solution to Project Euler problem 1
# Copyright (c) Dong-gi Kang. All rights reserved.
#
# https://github.com/DGKang234/Project_Euler_solution_py
# https://donggikang.com/category/project-euler/
#
'''
Q7 - 1000st 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 10001st prime number?
'''
def comp(num):
prime_list = lambda x:[i for i in range(2, x+1) if all([i % x for x in range(2, int(i**0.5+1))])][10000]
print (prime_list(num))
import time
if __name__ == "__main__":
start = time.process_time()
print(comp(120000))
print(f"----- process time : {time.process_time() - start} seconds -----")
# ----- process time : 0.663118 seconds -----
# ==================================================
def PrimeChecker(n):
if n < 2: return "Neither prime, nor composite"
for i in range(2, int(n**0.5) + 1):
if n % i == 0:
return False
return True
# returns the nth prime number
def PrimeOrder(n):
numberOfPrimes = 0
p = 1
while numberOfPrimes < n:
p += 1
if PrimeChecker(p):
numberOfPrimes += 1
return p
start = time.process_time()
print(PrimeOrder(10001))
print(f"----- process time : {time.process_time() - start} seconds -----")
#----- process time : 0.093947 seconds -----