def pe012(): """Find the smallest triangular number with over 500 divisors""" from tools import triangularGenerator, factorize gen = triangularGenerator() while True: num = next(gen) if len(factorize(num)) > 500: return num
def mod_sqrt(x, n, fact_n = []): if x == 0 or n == 0: return [0] elif n == 1: if x == 0: return [0] else: return [1] if not fact_n: fact_n = factorize(n) return mod_sqrt_pf(x, n, fact_n)
#!/usr/bin/env python import math from tools import factorize for i in range(1,40000): tri = i*(i+1)/2 factors = factorize(tri) div_count = reduce(lambda x,y: x*(y+1), factors.values(), 1) print "(i: %d|%d, %s): %s" % (i, tri, factors, div_count -1) if div_count > 500: break
The first three consecutive numbers to have three distinct prime factors are: 644 = 2^2 x 7 x 23 645 = 3 x 5 x 43 646 = 2 x 17 x 19. Find the first four consecutive integers to have four distinct primes factors. What is the first of these numbers? ''' from tools import factorize i = 120000 consec = 0 while i < 1000000: print i if len(factorize(i)) == 4: consec += 1 else: consec = 0 if consec == 4: print i break i += 1 print 'done'
#!/usr/bin/python ''' The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ? ''' from tools import factorize N = 600851475143 factors = factorize(N) print max(factors.keys())
def pe003(): """Find the largest prime factor of the number '600851475143'""" from tools import isPrime, factorize return max(filter(isPrime, factorize(600851475143)))