def cf_expansion(cf, i):
    """
    Produces the i-th term continued fraction expansion [num, denom] of the
    continued fraction representation given by cf.
    """
    p = len(cf) - 1 # period of the CF
    frac = [[1, 0], [cf[0], 1]]
    for j in range(2, i+1):
        a = cf[((j-2) % p) + 1]
        frac.append([
            a * frac[-1][0] + frac[-2][0],
            a * frac[-1][1] + frac[-2][1]
        ])
    return frac[i]