def isDivisible(n, divisors): for x in divisors: if n % x != 0: return False if not divisors: raise ValueError("Must provide at least one divisor!") return True if __name__ == "__main__": divisors = [x for x in range(20, 1, -1)] for x in divisors[:]: for y in factorise(x): if x != y and y in divisors: divisors.remove(y) prime_product = 1 for x in sieve(max(divisors)): if x in divisors: prime_product *= x n = prime_product while not isDivisible(n, divisors): n += prime_product print(n)
#! /usr/bin/python3 import sys, os sys.path.insert(0, os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../Problem 005'))) from factors import factorise if __name__ == "__main__": i = 1 tri = 0 divisors = [] while len(divisors) <= 500: tri += i divisors = factorise(tri) i += 1 print(tri)
def test_one(self): self.assertEqual(factorise(1), [1])
def test_square(self): self.assertEqual(factorise(4), [1, 2, 4])
def test_composite(self): self.assertEqual(factorise(6), [1, 2, 3, 6])
def test_two(self): self.assertEqual(factorise(2), [1, 2])