def factoring_visitor(state, primes):
 (f, lpart, pstack) = state
 factoring = []
 for i in range((lpart + 1)):
  factor = 1
  for ps in pstack[f[i]:f[(i + 1)]]:
   if (ps.v > 0):
    factor *= (primes[ps.c] ** ps.v)
  factoring.append(factor)
 return factoring

def factoring_visitor ( state , primes ) : ( f , lpart , pstack ) = state factoring = [ ] for i in range ( ( lpart + 1 ) ) : factor = 1 for ps in pstack [ f [ i ] : f [ ( i + 1 ) ] ] : if ( ps . v > 0 ) : factor *= ( primes [ ps . c ] ** ps . v ) factoring . append ( factor ) return factoring
use with multiset_partitions_taocp to enumerate the ways a number can be expressed as a product of factors .