-
Notifications
You must be signed in to change notification settings - Fork 0
/
primeGenerator.py
69 lines (35 loc) · 933 Bytes
/
primeGenerator.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
#implements a prime number sieve http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
def sieveofErat(lower, upper):
primes = [True] * math.abs(upper - lower)
for i in range(2,len(primes)):
l = 2
p = lower + primes.index(i)
while (p * l) < upper:
if primes[p * l] == True:
primes[p*l] = False
l += 1
return primes
numcases = raw_input()
cases = []
for i in range(0, int(numcases)):
m = raw_input().split()
cases.append(m)
print "\n"
for case in cases:
lower = int(case[0])
upper = int(case[1])
v = sieveofErat(upper)
for prime in v:
if (prime > lower or prime == lower) and (prime < upper or prime == upper):
print prime
print "\n"
#def sieveofErat(lower, upper):
# primes = [True] * math.abs(upper - lower)
# for i in primes:
# l = 2
# while i * l <= primes[-1]:
# if i * l in primes:
# primes[primes.indexof(i*l)] = False
# l += 1
# return primes
l