%I #149 Jan 05 2023 11:06:10
%S 3,2,9,5,8,3,19,10,7,649,15,4,33,17,170,9,55,197,24,5,51,26,127,9801,
%T 11,1520,17,23,35,6,73,37,25,19,2049,13,3482,199,161,24335,48,7,99,50,
%U 649,66249,485,89,15,151,19603,530,31,1766319049,63,8,129,65,48842,33
%N Smallest positive integer x satisfying the Pell equation x^2 - D*y^2 = 1 for nonsquare D and positive y.
%H Charles R Greathouse IV, <a href="/A033313/b033313.txt">Table of n, a(n) for n = 1..10000</a>
%H S. R. Finch, <a href="/A000924/a000924.pdf">Class number theory</a> [Cached copy, with permission of the author]
%H Bernard Frénicle de Bessy, <a href="https://gallica.bnf.fr/ark:/12148/bpt6k3187867/f33.item">Solutio duorum problematum circa numeros cubos et quadratos</a>, (1657). Bibliothèque Nationale de Paris. See column C page 19.
%H H. W. Lenstra, jr., <a href="http://www.ams.org/notices/200202/fea-lenstra.pdf">Solving the Pell Equation</a>, Notices of the AMS, Vol.49, No.2, Feb. 2002, p.182-192.
%H F. Richman and R. Mines, <a href="http://math.fau.edu/richman/pell-m.htm">Pell's equation</a>
%H Derek Smith, <a href="http://web.archive.org/web/20051125023958/http://www.lacim.uqam.ca/~plouffe/OEIS/archive_in_pdf/HistoricalPell.pdf">Historical Overview of Pell Equations</a>
%H Derek Smith, <a href="http://web.archive.org/web/20141029065638/http://www.plouffe.fr/simon/OEIS/archive_in_pdf/pellequations.pdf">The Search For An Exhaustive Solution to Pell's Equation</a>
%H Eric Weisstein's World of Mathematics, <a href="http://mathworld.wolfram.com/PellEquation.html">Pell Equation</a>
%F a(n) = sqrt(1 + A000037(n)*A033317(n)^2), or
%F a(n) = sqrt(1 + (n + floor(1/2 + sqrt(n)))*A033317(n)^2). - _Zak Seidov_, Oct 24 2013
%p F:= proc(d) local r,Q; uses numtheory;
%p Q:= cfrac(sqrt(d),'periodic','quotients'):
%p r:= nops(Q[2]);
%p if r::odd then
%p numer(cfrac([op(Q[1]),op(Q[2]),op(Q[2][1..-2])]))
%p else
%p numer(cfrac([op(Q[1]),op(Q[2][1..-2])]));
%p fi
%p end proc:
%p map(F, remove(issqr,[$1..100])); # _Robert Israel_, May 17 2015
%t PellSolve[(m_Integer)?Positive] := Module[{cf, n, s}, cf = ContinuedFraction[Sqrt[m]]; n = Length[Last[cf]]; If[n == 0, Return[{}]]; If[OddQ[n], n = 2n]; s = FromContinuedFraction[ContinuedFraction[Sqrt[m], n]]; {Numerator[s], Denominator[s]}];
%t A033313 = DeleteCases[PellSolve /@ Range[100], {}][[All, 1]] (* _Jean-François Alcover_, Nov 21 2020, after _N. J. A. Sloane_ in A002350 *)
%t Table[If[! IntegerQ[Sqrt[k]], {k,FindInstance[x^2 - k*y^2 == 1 && x > 0 && y > 0, {x, y},Integers]}, Nothing], {k, 2, 80}][[All, 2, 1, 1, 2]] (* _Horst H. Manninger_, Mar 28 2021 *)
%Y See A033317 (for y's).
%Y Cf. A000037, A002350, A077232, A077233.
%K nonn
%O 1,1
%A _Eric W. Weisstein_
%E Offset switched to 1 by _R. J. Mathar_, Sep 21 2009
%E Name corrected by _Wolfdieter Lang_, Sep 03 2015