Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions Prime/code.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
def SieveOfEratosthenes(range_to):

# creating a boolean array first
prime = [True for i in range(range_to + 1)]
p = 2
while (p * p <= range_to):

# If prime[p] is not changed, then it is a prime
if (prime[p] == True):

# Update all multiples of p
for i in range(p * 2, range_to + 1, p):
prime[i] = False
p += 1
print([p for p in range(2, range_to) if prime[p]])

def prime(range_from, range_to):

allList = [x for x in range(2, int(range_to)+1)]
allList = [x for x in range(2, range_to + 1)]

ptr = 0
while True:
i = 2
while i * allList[ptr] <= int(range_to):
while i * allList[ptr] <= range_to:
if i*allList[ptr] in allList:
allList.remove(i*allList[ptr])
i += 1
ptr += 1
if allList[ptr] ** 2 > int(range_to):
if allList[ptr] ** 2 > range_to:
break


primeList = [x for x in allList if x > int(range_from)]
primeList = [x for x in allList if x > range_from]
print("Prime List Between ", range_from, " and ", range_to, " is")
print(primeList)



if __name__ == "__main__":
print("Enter the range of number")
range_from = input("From: ")
range_to = input("To: ")
range_from = int(input("From: "))
range_to = int(input("To: "))

prime(range_from, range_to)
SieveOfEratosthenes(range_to)