import random
def gcd(a,b):
if a < b:
b = b - a
return gcd(a,b)
elif a > b:
a = a - b
return gcd(a,b)
else:
return a
def f(x,n):
return (x**2 + 1) % n
def PolRho(n):
x = random.randint(2,n)
y = x
d = 1
while d == 1:
x = f(x,n)
y = f(f(y,n),n)
print(x,y)
d = gcd(abs(x-y),n)
if d == n:
return PolRho(n)
return [d,n/d]
print(PolRho(16))
This is my code for Pollard's algorithm. The code works fine for 'print(PolRho(15))', but the kernel restarts if I try any other value for example 'print(PolRho(16))'