The continued fraction of a number n
is a fraction of the following form:
which converges to n
.
The sequence a
in a continued fraction is typically written as: [a0; a1, a2, a3, ... an].
We will write ours in the same fashion, but with the repeating part between semicolons.
Your goal is to return the continued fraction of the square root of n
.
Input: An integer, n
. n
will never be a perfect square.
Output: The continued fraction of sqrt(n)
.
Test Cases:
2 -> [1; 2;]
3 -> [1; 1, 2;]
19 -> [4; 2, 1, 3, 1, 2, 8;]
Shortest code wins. Good luck!