docs: def factorization( n ):
    """Decompose n into a list of (prime,exponent) pairs."""
  
    assert isinstance( n, integer_types )
  
    if n < 2: return []
  
    result = []
    d = 2
  
    # Test the small primes:
  
    for d in smallprimes:
      if d > n: break
      q, r = divmod( n, d )
      if r == 0:
        count = 1
        while d <= n:
          n = q
          q, r = divmod( n, d )
          if r != 0: break
          count = count + 1
        result.append( ( d, count ) )
  
    # If n is still greater than the last of our small primes,
    # it may require further work:
  
    if n > smallprimes[-1]:
      if is_prime( n ):   # If what's left is prime, it's easy:
        result.append( ( n, 1 ) )
      else:               # Ugh. Search stupidly for a divisor:
        d = smallprimes[-1]
        while 1:
          d = d + 2               # Try the next divisor.
          q, r = divmod( n, d )
          if q < d: break         # n < d*d means we're done, n = 1 or prime.
          if r == 0:              # d divides n. How many times?
            count = 1
            n = q
            while d <= n:                 # As long as d might still divide n,
              q, r = divmod( n, d )       # see if it does.
              if r != 0: break
              n = q                       # It does. Reduce n, increase count.
              count = count + 1
            result.append( ( d, count ) )
        if n > 1: result.append( ( n, 1 ) )
  
    return result