def main(): ''' ''' results = {} max_value = 10**7 for n in range(2, max_value+1): if not n % 10**4: print n factor_sum = reduce(operator.mul, map(lambda tup: tup[1]+1, euler.factor(n)), 1) results[n] = factor_sum matches = 0 for n in range(2, max_value): if results[n] == results[n+1]: matches += 1 print matches
from euler import factor # the euler module can find here : http://blog.dreamshire.com/2009/03/26/94/ ci = 1 nf = 4 #number of distinct factors ns = 4 #number of consecutive integers n = 2*3*5*7 #starting candidate for search while ci != ns: n += 1 if len(factor(n)) == nf: ci += 1 else: ci = 0 print "Answer to PE47 = ", n-nf+1
import euler print max(euler.factor(600851475143))
def rad(x): return reduce(operator.mul, map(operator.itemgetter(0), euler.factor(x)))
#!/usr/bin/python # coding: UTF-8 """ @author: CaiKnife Multiples of 3 and 5 Problem 1 If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Find the sum of all the multiples of 3 or 5 below 1000. """ from euler import factor bound = range(3, 1000) print sum([x for x in bound if factor(x)])
# The first two consecutive numbers to have two distinct # prime factors are: # # 14 = 2 x 7 # 15 = 3 x 5 # # 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 # prime factors. What is the first of these numbers? from euler import is_prime, factor def prime_factors(factorList): return len(factorList) == 4 notFound = True n = 1 while notFound: if prime_factors(factor(n)) and prime_factors(factor(n+1)) and prime_factors(factor(n+2)) and prime_factors(factor(n+3)): print n break n += 1
def main(): print(factor(600851475143)[-1][0])