Solution (source code)

= Solution

For the continued-fraction assertion, take the standard <Pell equation> hypothesis $N>0$ nonsquare. If $(x,y)$ is a solution with $x,y>0$, then
$$
\left|\frac xy-\sqrt N\right|
=\frac1{y^2(x/y+\sqrt N)}<\frac1{2y^2}.
$$
The convergent criterion for <continued fractions> therefore makes $x/y$ a convergent to $\sqrt N$. Write its periodic expansion as $[a_0;\overline{a_1,\ldots,a_\ell}]$, and index convergents by $p_j/q_j$ with $p_0/q_0=a_0$. The norm-one convergents occur at $j=k\ell-1$ with $k\ell$ even. In particular the fundamental positive solution comes at $\ell-1$ if $\ell$ is even, and at $2\ell-1$ if it is odd. If $\varepsilon=x_1+y_1\sqrt N>1$ is this least norm-one unit, all integer solutions are represented by $\pm\varepsilon^m$, $m\in\mathbb Z$.

The <abelian group> law comes from multiplication of the norm-one expressions:
$$
\boxed{(x_0,y_0)\circ(x_1,y_1)
=(x_0x_1+Ny_0y_1,\ x_0y_1+x_1y_0)}.
$$
Their <field norms> multiply, so the result remains a solution. Multiplication also proves associativity and commutativity; the identity is $(1,0)$ and the inverse of $(x,y)$ is $(x,-y)$. Cubing gives
$$
\boxed{(x,y)^{\circ3}
=(x^3+3Nxy^2,\ 3x^2y+Ny^3)
=(4x^3-3x,\ (4x^2-1)y)}.
$$
The last form uses $Ny^2=x^2-1$.

For completeness, the assertion about all powers follows by dividing any positive unit by the largest power of $\varepsilon$ not exceeding it: the remainder is a norm-one unit in $[1,\varepsilon)$, and minimality forces it to be $1$. Sign changes and inverses give the remaining solutions. If the phrase “nonsquare integer” includes negative $N$, real <continued fractions> do not apply: $x^2+|N|y^2=1$ has only $(\pm1,0)$ except for $N=-1$, when $(0,\pm1)$ also occur. The same multiplication law still works in those finite groups.