My program works for smaller numbers like 144,123, or 60 but seems to stop working when the numbers increase in magnitude. I've taken an introduction course in c++ and I vaguely remember overflows. However, I am not sure how python variables precisely work as the variable type does not seem to be explicitly declared. 1024 seems to be to small for an integer to overflow but perhaps I'm overlooking something within the recursion as I am only beginning to get the hang recursion. Can someone please explain to me why this algorithm breaks down at larger numbers?
Code
num = 1024
#Used to remove duplicates of the same prime
def simplify (num,prime):
if(num % prime == 0):
return simplify(num/prime,prime)
else:
return (num,num)
#used to find the prime factors
def pFact(num,a,b):
if a == 1:
return
elif b == 1:
print (a, "is a prime")
return pFact((simplify (num,a))[0],(simplify (num,a))[1],a)
elif a % b == 0:
return pFact(num,b,b-1)
elif a % b != 0:
return pFact (num,a,b-1)
elif b == 0:
return (num,num,num-1)
pFact(num,num,num-1)
Output
RecursionError: maximum recursion depth exceeded in comparison
Process returned 1 (0x1) execution time : 0.082 s Press any key to continue . . .