-
Notifications
You must be signed in to change notification settings - Fork 0
/
10001stPrime_p7.py
49 lines (40 loc) · 1.44 KB
/
10001stPrime_p7.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
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 2 09:21:16 2022
@author: INDHRNA
"""
"""
Problem 7
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?
"""
from time import time
start = time()
import numpy as np
import sympy as sp
import pandas as pd
#%%%
if __name__ == '__main__':
# =============================================================================
# method 1; using explicit for loop
# =============================================================================
lis = []
i = 0
limit = 1000000
counter = 10001
for num in np.arange(limit):
if sp.isprime(num):
i +=1
lis.append(num)
if i==counter: break
print(lis[-1])
# =============================================================================
# method 2; using pandas, no explicit loop, internally cython uses loop
# =============================================================================
df = pd.Series(np.arange(limit))
dff = (df[df.apply(lambda x: sp.isprime(x))]).reset_index()
print(dff.tail())
# =============================================================================
# method 3 ; direct method using sympy
# =============================================================================
print(f'{counter}^nth prime value is : {sp.prime(counter)}')