from typing import List
import math


def sqrt_frac(n: int) -> List:
    """
    Returns the continued fraction representation of sqrt(n)
    in the form [i; a_1, a_2, ..., a_n]

    Thanks to:
    https://math.stackexchange.com/questions/1198692/continued-fraction-expansion-for-%E2%88%9A7

    :param n: non-negative integer
    :return: continued fraction
    """
    if not n >= 0:
        raise ValueError

    whole = math.floor(math.sqrt(n))
    array = [whole]

    if whole - math.sqrt(n) == 0:
        return array

    # x/(sqrt(a) + b)
    first = (1 , n, -whole)
    rad = first

    while True:
        # (sqrt(a) + b)/x
        flipped = [rad[1], -rad[2], (rad[1] - rad[2]**2)//rad[0]]
        whole = math.floor((math.sqrt(flipped[0])+flipped[1])/flipped[2])
        flipped[1] -= whole*flipped[2]
        array.append(whole)
        rad = (flipped[2], flipped[0], flipped[1])

        if rad == first:
            break

    return array