def four_factor_iterator(): i = 2 while True: factors = primes.dictfactor(i) if len(factors) == 4: yield i i += 1
import primes allfactors = {} for i in xrange(1, 21): factors = primes.dictfactor(i) for factor, count in factors.items(): if factor not in allfactors.keys(): allfactors[factor] = 0 allfactors[factor] = max(allfactors[factor], count) answer = 1 for factor, count in allfactors.items(): answer *= factor ** count print answer
from primes import dictfactor trianglenum = 1 triangleindex = 1 while True: factors = dictfactor(trianglenum) factor_count = 1 for factorcount in factors.values(): factor_count *= factorcount + 1 if factor_count > 500: break triangleindex += 1 trianglenum += triangleindex print trianglenum