OFFSET
1,2
COMMENTS
For n > 2, a(n) <= ceiling(n/2)^2 - 1, since for m > 1, sqrt(m^2 - 1) has convergents (2m^2 - m - 1)/(2m - 1) and (2m^2 - 1)/(2m). Apparently, this bound is achieved only for n in {3, 4, 6, 7, 8, 10, 18}.
Is there an efficient algorithm for computing a(n)?
MATHEMATICA
a[n_] := Module[{a, b, r, q, v}, If[n == 1, Return[1]]; For[m = 1, True, m++, If[IntegerQ[Sqrt[m]], Continue]; r = Sqrt[m] // Floor; a = 0; b = 1; q = {1, 0}; While[q[[2]] < n && b != 0, v = Quotient[r+a, b]; a = b v-a; b = (m - a^2)/b; q = {{0, 1}, {1, v}}.q]; If[q[[2]] == n, Return[m]]]];
Array[a, 100] (* Jean-François Alcover, Oct 23 2020, after PARI code *)
PROG
(PARI) { A338307(n) = my(a, b, r, q, v); if(n==1, return(1)); for(m=1, oo, if(issquare(m), next); r=sqrtint(m); a=0; b=1; q=[1, 0]~; while(q[2]<n, v=(r+a)\b; a=b*v-a; b=(m-a^2)/b; q=[0, 1; 1, v]*q; ); if(q[2]==n, return(m)); ); }
CROSSREFS
KEYWORD
nonn
AUTHOR
Max Alekseyev, Oct 21 2020
STATUS
approved