Let $p$ be a prime number. Under what condition does there exist an integer $k$ such that $k^{2} \equiv-1$ $(\bmod p) ?$
Finding a necessary and sufficient condition requires mathematical tools that you do not have, but you can at least find a necessary condition. If $k^{2} \equiv -1 \pmod{p}$, then $k^{4} \equiv 1 \pmod{p}$, so the order of $k$ - the smallest exponent $n$ such that $k^n \equiv 1 \pmod{p}$ - divides 4. If $-1 \neq 1 \pmod{p}$, therefore if $p \neq 2$ (for $p=2$, the condition is satisfied), this order is not 2 because $k^{2} \equiv -1 \pmod{p}$, and it is certainly not 1 because if $k \equiv 1 \pmod{p}$, we would have $k^{2} \equiv 1 \pmod{p}$, so it is necessarily 4. Any other $n$ such that $k^n \equiv 1 \pmod{p}$ is divisible by the order 4 of $k$: otherwise, we would have $n = 4k + r$ with $0 \leq r < 4$ and $k^r \equiv 1 \pmod{p}$, which would contradict the minimality. Furthermore, by Fermat's theorem, since $k$ is not divisible by $p$ (otherwise we would have $k^{2} \equiv 0 \pmod{p}$), $k^{p-1} \equiv 1 \pmod{p}$, which implies that $p-1$ is divisible by 4. A necessary condition is therefore that $p=2$ or $p \equiv 1 \pmod{4}$.

Let's give an overview of the proof that this condition is sufficient. We work in the set of congruence classes modulo $p$: $a$ and $b$ are in the same class if $a \equiv b \pmod{p}$. This set of classes, $\mathbb{Z} / p \mathbb{Z}$, is equipped with addition and multiplication, because if $a \equiv b \pmod{p}$ and $a' \equiv b' \pmod{p}$, then $a + a' \equiv b + b' \pmod{p}$ and $aa' \equiv bb' \pmod{p}$. The elements $k$ and $-k$ have the same square: the "perfect squares" (we call them: quadratic residues) of $\mathbb{Z} / p \mathbb{Z}$ are therefore 0 and at most half of the other $p-1$ elements. In reality, it is exactly half of the other $p-1$ elements, and a given integer, for example -1, has "a one in two chance" of being a quadratic residue (for about half of the prime numbers, -1 is a quadratic residue). Because - and this is where it would be appropriate to delve deeper - the equation $x^2 = a$ cannot have more than two distinct roots, and more generally a polynomial of degree $d$ cannot have more than $d$ distinct roots, just as in the set of reals, for example. However, in $\mathbb{Z} / p \mathbb{Z}$, the equation $x^{p-1} = 1$ has $p-1$ distinct roots: all the non-zero elements of $\mathbb{Z} / p \mathbb{Z}$. If $p$ is odd and $x$ is non-zero, $x^{\frac{p-1}{2}}$ has a square of 1, so it is equal to either 1 or -1. If $x$ is a quadratic residue, there exists $y$ such that $y^2 = x$, so $x^{\frac{p-1}{2}} = y^{p-1} = 1$: all quadratic residues are roots of $x^{\frac{p-1}{2}} = 1$. But since there are $\frac{p-1}{2}$ quadratic residues, and this equation of degree $\frac{p-1}{2}$ cannot have more than $\frac{p-1}{2}$ roots, all its roots are quadratic residues. Therefore, if $(-1)^{\frac{p-1}{2}} = 1$, -1 is a quadratic residue. If $p \equiv 1 \pmod{4}$, $(-1)^{\frac{p-1}{2}} = 1$, hence the result.