Find all non-negative integers $n$ satisfying $2^{n}\equiv n^{2} mod\, 5$ I'm trying to find all non-negative integers $n$ satisfying $2^{n}\equiv n^{2}\pmod{5}$.  
So far, all the progress I've made is figuring out that $n^{2} mod \, 5$ for $n=1$ to $5$ has the pattern "$1,\, 4,\, 4,\, 1,\, 0$" which repeats $mod \, 5$. Then, I started looking at powers of $2$ to see if there was a pattern to when they are $0,\,1,\,\text{and}\, -1\, mod\, 5$. I saw that when $n = 4k$, where $k$ is an integer $\geq 0$, $2^{n}\,mod\,5 = 1$; for $n=5k$, where $k$ is an integer $\geq 0$, $2^{n} \, mod\, 5 = -1$; and there exists no $n$ such that $2^{n} \,mod\, 5 = 0$.
But, I found no pattern as to when $2^{n}\mod 5 = n^{2}\,\mod\,5$, so then I can find all the $n$'s that give me the divisibility I want.
No hints, please, I'm not a number theorist and am really out of my comfort zone. Just complete answers, so I can figure out how problems that look like this are supposed to be done.
Thank you in advance
 A: The powers of $2$ mod $5$ repeat with period $4$, and the squares repeat with period $5$.  Thus $(2^n - n^2) \mod 5$ repeats with period $20$.
For $0 \le n \le 19$ you get
$$ \matrix{n & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10 & 11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 \cr
n^2 \mod 5  & 0 & 1 & 4 & 4 & 1 & 0 & 1 & 4 & 4 & 1 & 0 & 1 & 4 & 4 & 1 & 0 & 1 & 4 & 4 & 1 \cr
2^n \mod 5 & 1 & 2 & 4 & 3 & 1 & 2 & 4 & 3 & 1 & 2 & 4 & 3 & 1 & 2 & 4 & 3 & 1 & 2 & 4 & 3 \cr}$$
Thus $2^n \equiv n^2 \mod 5$ for $n \equiv 2, 4, 16$, or $18 \mod 20$.
A: Here is a slightly different perspective from the answer by Robert.  I personally his solution, as with the range of numbers we are looking at, explicitly computing everything is decently fast and clean, and explicitly invoking the chinese remainder theorem is a bit more work, but I figure it is instructive.
For every $k$, let us try to solve both $2^n\equiv k\pmod 5$ and $n^2\equiv k\pmod 5$.  First, we note that, since $2$ is invertible mod 5, so is every power of $2$, and thus $2^n \equiv 0 \pmod 5$ has no solutions.  Similarly, we can explicitly square all the numbers mod 5 to see that the only squares are $0,1,4$.  Therefore, the only values of $k$ we need to consider are $1$ and $4$.
(Case $k=1$) By Euler's theorem, $2^n$ has period $4$, and computing, we have $2^n\equiv 1,2,4,3$ respectively for $n=0,1,2,3$.  So we want to consider $n\equiv 0 \pmod 4$.  Similarly, we can compute that $n^2\equiv 1$ when $n\equiv 1,4 \pmod 5$.  The chinese remainder theorem tells us that there is one solution mod 20 to $n\equiv 0 \pmod 4$ and $n\equiv 1 \pmod 5$.  Similarly, there is one solution mod 20 to $n\equiv 0 \pmod 4$ and $n\equiv 4 \pmod 5$.  
To actually find the solutions, there are multiple ways to proceed.  Since we will need to solve 4 total pairs of equations (2 when $k=1$, 2 when $k=4$), I like the following approach, analagous to Lagrange interpolation for polynomials.
Proposition: Suppose that $x,y\in \mathbb Z$ such that $x\equiv 1 \pmod p$, $x\equiv 0 \pmod q$, and $y\equiv 0 \pmod p$, $y\equiv 1 \pmod q$.  Then $ax+by\equiv a\pmod p$ and $b\pmod q$.  Moreover, if $p$ and $q$ are relatively prime, then this is the unique solution mod $pq$.
If $p$ and $q$ are large, there are algorithms we can employ to find our $(x,y)$ pair as in the proposition, but you can verify here that $(5,16)$ works.  So to find a solution to $n\equiv 0 \pmod 4$ and $n\equiv 4 \pmod 5$, we take $0*5+4*16\equiv 4\pmod{20}$
The case $k=4$ is similar.
