Professional Documents
Culture Documents
Pollad Rho Complex
Pollad Rho Complex
def PollardRho(n):
f = lambda x: x*x + 2
x, y, d= 2, 2, 1
cp = 0
while d==1:
cp = cp + 1
x = f(x)%n
y = f(f(y))%n
d = gcd(abs(x-y),n)
return d,cp
def PollardRho2(n):
f = lambda x: x*x + 2
x, y, d= 2, 2, 1
cp = 0
m = 10
tmp = 1
while d==1:
cp = cp + 1
x = f(x)%n
y = f(f(y))%n
tmp = (tmp*abs(x-y))%n
if cp%m == 0:
d = gcd(tmp,n)
return d,cp
def algoNif(n):
cp = 0
for i in range(3,(int)(math.sqrt(n)),2):
cp = cp+1
if n%i == 0:
return i,cp
return ""
if __name__ == '__main__':
print("Enter an integer")
n = int(input())
###__PollardRho__###
dep = time()
d,cp = PollardRho(n)
temp = time()-dep
print("Method PollardRho")
if d==1 or d==n:
print("The number is prime")
else:
print("The number is not prime")
###__PollardRhoAmeliore__###
dep = time()
d,cp = PollardRho2(n)
temp = time()-dep
###__MethodNaif__###
dep = time()
d, cp =algoNif(n)
temp = time() - dep
print(n, "=", d, "*", (int)(n/d))
print(cp, "tour")
'''print(d)'''
print("Temps: ", temp)