Question: For which number $m$ the following equation has a solution? $$n^2 \equiv -1 \mod m $$
Remark: The code below provides the first such numbers: $1,2,5,10,13,17$.
By searching this sequence on OEIS, we find the expected numbers: A008784 (we took its title).
This link contains the following statement:
Numbers whose prime divisors are all congruent to 1 mod 4, with the exception of at most a single factor of 2. - Franklin T. Adams-Watters, Sep 07 2008
Then, the question reduces to prove the above statement.
sage: for m in range(20):
....: for n in range(m):
....: if (n**2+1).mod(m)==0:
....: print([m])
....:
[1]
[2]
[5]
[5]
[10]
[10]
[13]
[13]
[17]
[17]