-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwqu_project_ip.py
119 lines (110 loc) · 3.23 KB
/
wqu_project_ip.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
def mersenne_number(p):
return (2 ** p) - 1
def mersenne_number_reverse(p):
return (p ** 1/2) - 1
##
def is_prime(number):
if number <= 1: return False
for factors in range(2, number):
if number % factors == 0: return False
## elif number % 3 == 0: return False
## elif number % 5 == 0: return False
return True
##
def get_primes(n_start, n_end):
temp = list()
for number in range(n_start, n_end):
if is_prime(number):
temp.append(number)
return temp
primes_list = get_primes(3,65)
print('primes = ', primes_list)
##
##mersennes = [number for number in get_primes(3,65) if mersenne_number(number)]
##print('mersennes = ', mersennes)
##
####y = [number for number in mersennes if mersenne_number(number)]
####print('y = ', y)
##mersennes_primes = list()
##a = range(3, 65)
##for num in a:
## if mersenne_number(num) in a:
## mersennes_primes.append(num)
##print(mersennes_primes)
##def lucas_lehmer (p):
## n0 = 4
## np = 0
## n = list()
## for i in (range(p-2+1)):
## if i == 0:
## np = ((n0 ** 2) - 2) % ((2 ** p) - 1)
## else:
## np = ((np ** 2) - 2) % ((2 ** p) - 1)
## n.append(np)
## return n
def ll_prime(p):
count = list()
mersennes = list()
a = list(range(3,p))
for num in a:
check = is_prime(num)
if check == mersenne_number(num):
mersennes.append(num)
count.append(True)
else:
mersennes.append(num)
count.append(False)
mersennes = list(zip(mersennes,count))
return mersennes
ll_prime(65)
def ll_prime2(p=list(range(3,65))):
count = list()
mersennes = list()
for p in p:
number = is_prime(p)
if mersenne_number(number):
mersennes.append(p)
count.append(True)
else:
mersennes.append(p)
count.append(False)
mersennes_final = list(zip(mersennes,count))
return mersennes_final
def ll_prime2_1(p=get_primes(3,65)):
count = list()
mersennes = list()
for p in p:
number = is_prime(p)
if mersenne_number(number):
mersennes.append(p)
count.append(True)
else:
mersennes.append(p)
count.append(False)
mersennes_final = list(zip(mersennes,count))
return mersennes_final
import math
def is_prime_fast(number):
if number <= 1: return False
if number == 2: return True
if number == 3: return True
if number == 5: return True
#for factor in range(3,number):
if number % 2 == 0 or number % 3 == 0 or number % 5 == 0 or number % 7 == 0:
return False
return True
def get_primes_fast(n_start, n_end):
temp = list()
for number in range(n_start, n_end):
if is_prime_fast(number):
temp.append(number)
return temp
import math
def is_prime_fast2(number):
if number <= 1: return False
if number == 2: return True
if number > 2 and number % 2 == 0: return False
for factor in range(2,number):
if factor % 2 == 0 or factor < math.sqrt(number):
return True
return False