def pollard_pm1(n, B=10, a=2, retries=0, seed=1234):
 n = int(n)
 if ((n < 4) or (B < 3)):
  raise ValueError('pollard_pm1 should receive n > 3 and B > 2')
 prng = random.Random((seed + B))
 for i in range((retries + 1)):
  aM = a
  for p in sieve.primerange(2, (B + 1)):
   e = int(math.log(B, p))
   aM = pow(aM, pow(p, e), n)
  g = igcd((aM - 1), n)
  if (1 < g < n):
   return int(g)
  a = prng.randint(2, (n - 2))

def pollard_pm1 ( n , B = 10 , a = 2 , retries = 0 , seed = 1234 ) : n = int ( n ) if ( ( n < 4 ) or ( B < 3 ) ) : raise ValueError ( 'pollard_pm1 should receive n > 3 and B > 2' ) prng = random . Random ( ( seed + B ) ) for i in range ( ( retries + 1 ) ) : aM = a for p in sieve . primerange ( 2 , ( B + 1 ) ) : e = int ( math . log ( B , p ) ) aM = pow ( aM , pow ( p , e ) , n ) g = igcd ( ( aM - 1 ) , n ) if ( 1 < g < n ) : return int ( g ) a = prng . randint ( 2 , ( n - 2 ) )
use pollards p-1 method to try to extract a nontrivial factor of n .