Find all positive integers $n$, such that $(\left\lfloor \sqrt{n} \right\rfloor^{2} +2) | (n^2 + 1) $ I tried to look at the cases when $n$ is a perfect square. Then $\left\lfloor \sqrt{n} \right\rfloor^{2} +2= n+2$, $ n^2 + 1 =(n-2)(n+2) + 5$. Then we must have $(n+2)|5$.
But only $1$ and $5$ divide $5$. Thus, $n=3$, but that is not a solution since we assumed $n$ to be a perfect square. The problem therefore has no perfect-square solutions.
I'm not sure how relevant this is to the general case, but I did not manage to get any further.
Thank you for your help in advance.
 A: Let $m^2=n-k$ be the largest square less than or equal to $n$.
$\implies0\le k\le 2m$
We have $n-k+2|n^2+1$
$$\implies n-k+2|1+n(k-2)$$
$$\implies n-k+2|k^2-4k+5$$
$$\implies m^2+2|k^2-4k+5$$
$\dfrac{k^2-4k+5}{m^2+2}=1,2\text{ or }3$ otherwise the inequality $0\le k\le 2m$ is violated.

If $\dfrac{k^2-4k+5}{m^2+2}=1$ we then have $(k-m-2)(k+m-2)=1$.
The only solutions for the above equality are $(m,k)=(0,1),(0,3)$, but $k>2m$, so no solution exists.

$\dfrac{k^2-4k+5}{m^2+2}=2$ we then have $(k-2)^2+1=2m^2+4$. $k$ should be odd. The LHS is of the form $8k+2$ while RHS is of the form $8k+4$ or $8k+6$. So no solution exists.

If $\dfrac{k^2-4k+5}{m^2+2}=3$ we then have $(k-2)^2+1=3m^2+6$. $3$ never divides the LHS so there are no  solutions.
A: Without knowing the source of the problem, I give here only a hint toward the solution.

Write $m = \lfloor n\rfloor$, so that $m^2 \leq n < (m + 1)^2$.
Write $n = m^2 + r$, so that $0\leq r \leq 2m$.
The condition then becomes $m^2 + 2 \mid (m^2 + r)^2 + 1$, which is equivalent to $m^2 + 2 \mid (r - 2)^2 + 1$.
