def p12(): """ Highly divisible triangular number The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, ... Let us list the factors of the first seven triangle numbers: 1: 1 3: 1,3 6: 1,2,3,6 10: 1,2,5,10 15: 1,3,5,15 21: 1,3,7,21 28: 1,2,4,7,14,28 We can see that 28 is the first triangle number to have over five divisors. What is the value of the first triangle number to have over five hundred divisors? """ import sys sys.path.append("../idea bag/") from prime_factors import factors index = 1 triangular = 1 divisors = 0 while divisors < 500: index += 1 triangular += index divisors = len(factors(triangular)) + 2 return triangular
def test_no_factors(self): self.assertEqual(factors(1), [])
def test_factors_include_a_large_prime(self): self.assertEqual(factors(93819012551), [11, 9539, 894119])
def test_product_of_primes(self): self.assertEqual(factors(901255), [5, 17, 23, 461])
def test_product_of_primes_and_non_primes(self): self.assertEqual(factors(12), [2, 2, 3])
def test_cube_of_a_prime(self): self.assertEqual(factors(8), [2, 2, 2])
def test_square_of_a_prime(self): self.assertEqual(factors(9), [3, 3])
def test_prime_number(self): self.assertEqual(factors(2), [2])
def test_power_of_two(self): self.assertEqual(factors(1073741824), [2] * 30)
def test_cube_of_a_prime(self): self.assertEqual(factors(617**3), [617, 617, 617])
def test_cube_of_a_non_prime(self): self.assertEqual(factors(27**3), [3, 3, 3, 3, 3, 3, 3, 3, 3])
def test_square_of_a_prime_2(self): self.assertEqual(factors(625), [5, 5, 5, 5])
def test_prime_number_3(self): self.assertEqual(factors(9539), [9539])
def test_prime_number_2(self): self.assertEqual(factors(17), [17])
def test_factors_include_a_very_large_prime(self): self.assertEqual(factors(2 ** 1000), [2] * 1000)
def is_abundant(number): return number <= sum(factors(number))