PollardRho Namespace Reference


Functions

def gcd
def rho
def factor

Variables

tuple n = int( sys.argv[ i ])
tuple f = factor( n )

Function Documentation

def PollardRho::factor (   n  ) 

Definition at line 89 of file PollardRho.py.

00089                :
00090     ans = [ ]
00091     print "%d" % ( n )
00092     if n == 1:
00093         print "a: %d" % ( n )
00094         ans.append( n )
00095     else:
00096         divisor = rho( n )
00097         dividend = n / divisor
00098         print "b: %d %d" % ( divisor, dividend )
00099         ans.append( divisor )
00100         ans.append( factor( dividend ) )
00101     return ans
00102  
00103 #     public static void main(String[] args) {
00104 #         BigInteger N = new BigInteger(args[0]);
00105 #         factor(N);
00106 #    }
00107 #}
00108 
00109 
if __name__ == '__main__':

def PollardRho::gcd (   a,
  b 
)

Euclid's algorithm for integer greatest common divisors.

Definition at line 53 of file PollardRho.py.

00053                :
00054     """
00055     Euclid's algorithm for integer greatest common divisors.
00056     """
00057 
00058     while b:
00059         a, b = b, a % b
00060     return a
00061 
def rho( n ):

def PollardRho::rho (   n  ) 

Definition at line 62 of file PollardRho.py.

00062             :
00063     c = int( 100 * random( ) )
00064     x = int( 100 * random( ) )
00065     c = 17
00066     x = 19
00067 #    print c, x
00068     xx = x
00069     if ( n %  2 == 0):
00070         return 2
00071     while ( 1 ) :
00072         x  = ( x  * x  % n + c ) % n
00073         xx = ( xx * xx % n + c ) % n
00074         xx = ( xx * xx % n + c ) % n
00075         divisor = gcd( n, abs( x - xx ) )
00076         if divisor != 1:
00077             break
00078 
00079     print "d: %d" % divisor
00080     return divisor
00081 
00082 #     public static void factor(BigInteger N) {
00083 #         if (N.compareTo(ONE) == 0) return;
00084 #         if (N.isProbablePrime(20)) { System.out.println(N); return; }
00085 #         BigInteger divisor = rho(N);
00086 #         factor(divisor);
00087 #         factor(N.divide(divisor));
00088 #    }
def factor( n ):


Variable Documentation

tuple PollardRho::f = factor( n )

Definition at line 115 of file PollardRho.py.

tuple PollardRho::n = int( sys.argv[ i ])

Definition at line 114 of file PollardRho.py.


Generated on Sun Mar 22 09:59:14 2009 for Multiperfect Number Generator by  doxygen 1.5.8