-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprime_finder.py
79 lines (71 loc) · 1.84 KB
/
prime_finder.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import numpy as np
from mpmath import mp
import pandas as pd
mp.dps = 200
e = str(mp.e)
pi = str(mp.pi)
phi = str(mp.phi)
euler = str(mp.euler)
catalan = str(mp.catalan)
apery = str(mp.apery)
khinchin = str(mp.khinchin)
mertens = str(mp.mertens)
primes = []
def prime_check(start, end):
for num in range(start, end + 1):
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
primes.append(str(num))
# x must be Integer, number must be String
def slow_check(number, x): # x is the order of prime
prime_check(10**(x - 1), (10**x) - 1)
for z in range(mp.dps - 1):
if number[2 + z: 2 + z + x] in primes:
print(number[2 + z: 2 + z + x])
def fast_check(number, x):
for z in range(mp.dps - 2):
num = int(number[2 + z: 2 + z + x])
if num > (10**(x-1)):
for i in range(2, int((num/2) + 1)):
if (num % i) == 0:
break
else:
print(num)
def number_input():
answer = input("""
Select your number:
A: Pi (π)
B: Base of Natural Log (e)
C: Golden Ratio (φ)
D: Euler's Constant (γ)
E: Catalan's Constant (G)
F: Apéry's Constant (ζ(3))
G: Khinchin's Constant (K0)
H: Mertens' Constant (M)
""")
switcher = {
"A": pi,
"a": pi,
"B": e,
"b": e,
"C": phi,
"c": phi,
"D": euler,
"d": euler,
"E": catalan,
"e": catalan,
"F": apery,
"f": apery,
"G": khinchin,
"g": khinchin,
"H": mertens,
"h": mertens
}
return switcher.get(answer)
if __name__ == "__main__":
fast_check(number_input(), int(input("""
What length prime numbers shall we find? (in digits)
""")))