forked from fhcwcsy/python_practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathveryNewPrime.py
More file actions
84 lines (74 loc) · 2 KB
/
Copy pathveryNewPrime.py
File metadata and controls
84 lines (74 loc) · 2 KB
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
def generating_prime( a, b ):
# 134 15183
# 21344 66666
# 5 1245122
# 3 310831
# 1 1
# prime_list = []
# not_prime_list = []
# if a % 2 :
# a += 1
# for num in range( a, b+1, 2 ) :
# if num in not_prime_list :
# continue
# not_prime = True
# for d in range( 3, int( a**0.5 ) + 1, 2 ) :
# if d in not_prime_list :
# continue
# if not num % d :
# not_prime = True
# break
# if not_prime:
# continue
prime_list = []
save = True
start = 0
next_num = 3
all_possibilities = set( range( a, b+1 ) )
if b < 2:
return []
while next_num <= b :
is_prime = True
for d in prime_list :
if d > next_num*0.5:
break
if next_num % d == 0 :
is_prime = False
break
if is_prime :
prime_list.append( next_num )
# print( next_num )
if save and prime_list[-1] >= a :
start = prime_list.index( next_num )
save = False
next_num += 2
if a <= 2:
prime_list.insert(0, 2 )
return prime_list[ (start) : ]
save = True
start = 0
next_num = 3
all_possibilities = set( range( a, b+1 ) )
if b < 2:
return []
while next_num <= b :
is_prime = True
for d in prime_list :
if d > next_num*0.5:
break
if next_num % d == 0 :
is_prime = False
break
if is_prime :
prime_list.append( next_num )
# print( next_num )
if save and prime_list[-1] >= a :
start = prime_list.index( next_num )
save = False
next_num += 2
if a <= 2:
prime_list.insert(0, 2 )
return prime_list[ (start) : ]
# if __name__ == "__main__":
# print( generating_prime( 5, 1240 ) )
# generating_prime( 5, 1245122 )