from decimal import Decimal


def F(n):
    """Calculate n-th Fibonacci number using closed form expression.
    Note, this is only accurate for F(i) for i in [0, 124]. Diviation
    of 1 for i = 125, and worse after that.

    This can be improved by:
        from decimal import getcontext
        getcontext().prec = <wanted precision>

    With prec set to 100, F(i) is accurate up to i = 471.
    With prec set to 212, F(i) is accurate past i = 1000
    """
    sqrt5 = Decimal(5).sqrt()
    numerator = (Decimal(1) + sqrt5)**Decimal(n) - (Decimal(1)-sqrt5)**Decimal(n)
    denomenator = Decimal(2)**Decimal(n) * sqrt5
    return int((numerator / denomenator).to_integral_value())