Continued Fraction can be find in http://mathworld.wolfram.com/ContinuedFraction.html
Function ContinuedFraction(ByVal n As Long) Dim root As Long, p As Long, q As Long, b() As String, temp As Long, i As Long root = Int(Sqr(n)) p = root q = n - p * p If q = 0 Then ContinuedFraction = "{}": Exit Function Do While temp <> 2 * root temp = (root + p) / q i = i + 1 ReDim Preserve b(1 To i) b(i) = temp p = temp * q - p q = (n - p * p) / q Loop ContinuedFraction = "{" & Join(b, ",") & "}" End Function Sub main() Debug.Print ContinuedFraction(99999) End Sub
It returns:
{4,2,2,1,2,24,1,13,10,1,1,1,5,3,1,13,3,2,2,16,1,2,7,70,7,2,1,16,2,2,3,13,1,3,5,1,1,1,10,13,1,24,2,1,2,2,4,632}