from math import sqrt

print('''
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
    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?
''')

# Factorization
# Make a function 'factor' that finds the first prime divisor for any given number. Store those divisors, this is the factorization.
# Make a function that finds all subsets of the set of your exponents


def factor(num):
    end = int(sqrt(num)+1)
    for ab in xrange(2, end):
        if num % ab == 0:
            return ab
    return num

def factorize(triangle):
    factorization = []
    while True:
        fact = factor(triangle)
        factorization.append(fact)
        triangle = triangle / factorization[-1]
        if triangle == 1:
            break
    return factorization

def exponenticize(factors):
    exponents = [1]
    count = 1
    for ab in factors:
        try:
            if ab == factors[count]:
                exponents[-1] += 1
            else:
                exponents.append(1)
        except:
            break
        count += 1
    return exponents

triangle = 25
for ab in range(10, 27):
    triangle = ab
    print factorize(triangle), exponenticize(factorize(triangle))





