Let $\mathbb{N}$ denote the set of the positive integers. We consider the following function $f:\mathbb{N}\times \mathbb{N}\to \mathbb{Q}$: $$f(a,b)=\frac{a^2+b^2}{1+ab} \text{ for all } a,b\in\mathbb{N}.$$
This function has the [amusing property](https://www.youtube.com/watch?v=Y30VF3cSIYQ) that if $f(a,b)$ is an integer, then it is a square number.


We consider the following sets:


1. $W\_0 = \{n\in\mathbb{N}: f^{-1}(\{n^2\}) = \emptyset\}$,
2. $W\_\infty = \{n\in\mathbb{N}: |f^{-1}(\{n^2\})| = \aleph\_0\}$, and
3. $W\_\text{fin} = \mathbb{N} \setminus (W\_0\cup W\_\infty)$.


What are the cardinalities of $W\_0, W\_\infty, W\_\text{fin}$?



Function on quadratic numbers
$W\_\infty=\mathbb N\setminus\{1\}$. To see this, note that for $n>1$ we have a solution $(a,b)=(n,n^3)$ with $a<b$, and if we have one such solution, then $(b,n^2b-a)$ is another one (straightforward calculation) with $b<n^2b-a$, from which we easily construct an infinite sequence of distinct solutions.


For $n=1$, we just have to note that $f(a,b)=1$ iff $a^2-ab+b^2=1$ iff $(2a-b)^2+3b^2=4$ which is easily seen to have only one solution $(1,1)$ in $\mathbb N^2$, so $W\_\text{fin}=\{1\}$.


Since you explicitly asked for the cardinalities of the respective sets: $|W\_0|=0,|W\_\text{fin}|=1,|W\_\infty|=\aleph\_0$.


Edit: proof that the pairs described in the first paragraph are, up to symmetry, all the solutions.


Suppose $(k,l),0<k<l$ were a solution not constructed in the above way. Moreover, let this be such a solution with minimal $k$ possible. Then $(n^2k-l,k)$ is a solution. We easily see $0\leq n^2k-l<k$. If $n^2k-l=0$, then we verify that $(k,l)$ was in fact a solution $(n,n^3)$, contradicting choice of $(k,l)$. If it is positive, then by minimality of $k$ it is one of the solutions $(a,b)$ constructed above. But then $(k,l)=(b,n^2b-a)$, again contradicting the choice of $(k,l)$. So the construction gives us all solutions.


