Ejemplo n.º 1
0
def solve():
    def p(i):
        return i * (3 * i - 1) / 2

    j = 1

    while True:
        j += 1
        pj = p(j)

        for k in reversed(range(1, j)):
            pk = p(k)

            if is_pentagonal(pj - pk) and is_pentagonal(pj + pk):
                return int(pj - pk)
def solve():
    # t(n)      = n(n + 1) / 2      für n = 2n - 1
    #           = (2n - 1)(2n - 1 + 1) / 2
    #           = (2n - 1)(2n) / 2
    #           = n(2n - 1)
    #           = h(n)
    #
    # Therefore t(n) is a subset of h(n)
    def h(n):
        return n * (2 * n - 1)

    # Start from 144 as the answer must be greater than h(143)
    i = 144

    while True:
        formula = h(i)
        if is_pentagonal(formula):
            return formula

        i += 1