forked from fhcwcsy/python_practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenPrimeNew.py
More file actions
29 lines (26 loc) · 715 Bytes
/
Copy pathgenPrimeNew.py
File metadata and controls
29 lines (26 loc) · 715 Bytes
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
import sys
# def is_prime( n ):
# return True
def generating_prime(a,b):
prime_list = []
not_prime_dict = []
for n in range( a, b+1 ) :
if not n % 2 :
continue
if n == 1 :
continue
if not n in not_prime_dict :
p = False
for i in range( 2, int(n**0.5)+1 ) :
if not n % i :
p = True
break
if p :
continue
prime_list.append( n )
not_prime_dict.extend( range( 2*n, b, n) )
else:
not_prime_dict.remove( n )
return prime_list
# if __name__ == "__main__":
# print( generating_prime( 1, 101 ) )