Brent's variation of a factorization algorithm

MRAB python at mrabarnett.plus.com
Tue Dec 8 13:51:29 EST 2009


Gabriel Genellina wrote:
> En Fri, 27 Nov 2009 12:36:29 -0300, n00m <n00m at narod.ru> escribió:
> 
>> Maybe someone'll make use of it:
>>
>>
>> def gcd(x, y):
>>     if y == 0:
>>         return x
>>     return gcd(y, x % y)
>>
>> def brent(n): ...
> 
> A better place to publish this code would be the Python Cookbook: 
> http://code.activestate.com
> 
An iterative alternative is:

def gcd(x, y):
     while y != 0:
         x, y = y, x % y
     return x




More information about the Python-list mailing list