OFFSET
0,7
COMMENTS
The continued fraction expansion of sqrt(n) is periodic (where n is no square), and the period splits in two halves which are mirrored around the center. With r = floor(sqrt(n)) the expansion takes one of the forms:
[r; i, j, k, ..., m, m, ..., k, j, i, 2*r] (odd period length) or
[r; i, j, k, ..., m, ..., k, j, i, 2*r] (even period length)
[r; 2*r] (empty symmetric part, for n = r^2 + 1)
This sequence lists the central element(s) m, or 0 for n = r^2 + 1, or -1 for n = r^2.
a(k^2-1) = 1 for k >= 2. - Robert Israel, Nov 04 2019
LINKS
Robert Israel, Table of n, a(n) for n = 0..10000
Georg Fischer, Table of the continued fractions of sqrt(0..20000)
Oskar Perron, Die Lehre von den Kettenbrüchen, B. G. Teubner (1913), section 24, p. 87 ff.
EXAMPLE
CF(sqrt(2906)) = [53;1,9,1,3,1,3,1,1,14,1,5,2,2,5,1,14,1,1,3,1,3,1,9,1,106], odd period, two central elements, a(2906) = 2.
MAPLE
f:= proc(n) local L, m;
if issqr(n) then return -1
elif issqr(n-1) then return 0
fi;
L:= numtheory:-cfrac(sqrt(n), periodic, quotients);
m:= nops(L[2]);
L[2][floor(m/2)]
end proc:
map(f, [$0..100]); # Robert Israel, Nov 04 2019
MATHEMATICA
Array[Which[IntegerQ@ Sqrt@ #, -1, IntegerQ@ Sqrt[# - 1], 0, True, #[[Floor[Length[#]/2]]] &@ Last@ ContinuedFraction@ Sqrt@ #] &, 83, 0] (* Michael De Vlieger, Jul 07 2019 *)
CROSSREFS
KEYWORD
sign,look
AUTHOR
Georg Fischer, Jun 24 2019
STATUS
approved