# first find the triangle numbers # then find the factors of the triangle numbers # then count the factors # find the first number that is a triangle that has over 500 divisors from common import factorize from itertools import combinations as combo number = 0 count = 1 num_factors = 0 TARGET = 500 while num_factors <= TARGET: number += count num_factors = len(factorize(number)) count += 1 print number, num_factors # THIS IS TOO INEFFICIENT # from common import prime_factors, product, factorize # from itertools import combinations_with_replacement as combo # TARGET = 5 # num_factors = 0
# Problem 5 # 30 November 2001 # 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. # What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? from common import factorize, merge_with_max, product from functools import reduce t = reduce(merge_with_max, (factorize(x) for x in range(2, 21))) print(product(k ** v for k, v in t.items()))