I have edited a piece of code which gives feedback for prime numbers on a large scale. If the number is Prime it will result with a two digit number that ends in zero and it will show two of the same numbers. For composite a number it will show two numbers that don't end in ZERO. You would input the number in this fashion for a composite input range(2^8-2, 2^8)--output__54 54 or for a prime input range(2^7-2, 2^7)--output is __30 30
However I'm getting a recursive error. Is there a way to rewrite the code, so that it does not use recursion or is there a work around the recursion. I have tried increasing the sys overhead, but it did not work.
I noticed the recursion error when I tried 11.
Here is the code if someone can help me code it so recursion does not come up?
def isPrime(n):
isPrime = True
def is_divisible(n,divisor):
if n<(divisor-1)*divisor: return False
if n%divisor==0: return True
else:
divisor += 1
return is_divisible(n,divisor)
if n==2:
isPrime = True
elif is_divisible(n,divisor=2):
isPrime = False
return isPrime
def getNumPrimes(n):
if n <= 2:
return 0
else:
return isPrime(n-1) + getNumPrimes(n-1)
for n in range(2**11-2,2**11):
print(getNumPrimes(n))