Number of solutions for $x^2 \equiv x \pmod m$ What is the number of solutions of $x^2 \equiv x \pmod m$ for any positive integer $m$?

So we get $x(x-1) \equiv \mod m$ so $m|x(x-1)$.  If $m$ is prime then either $m|x$ and $x \equiv 0 \mod m$ or $m|x -1$ and $x \equiv 1 \mod m$.
But what if $m$ is not prime.  If $m = \prod p_i^{k_i}$ then as $x$ and $x-1$ are relatively prime (they have only a difference of 1) then each $p_i^{k_i}|x$ or divides $x -1$.
In other words we need to find $x \equiv 0 \mod k$ and $x \equiv 1 \mod (j)$ where $m = j*k$ and $\gcd(j,k) = 1$ (Note if $m = \prod p_i^{k_i}$ there will by $2^i$ such sets of equations).  According to the chinese remainder theorem there will be one solution to each set of problems. (So $2^i$ solutions total).
Example 1
Solve $x^2 = x \mod 12 \iff x(x-1) \equiv 0 \mod m$.  $12 = 3 \times 4$ so there will be the following solutions:
A) $x \equiv 0 \mod 12$ and $x \equiv 1 \mod 1$ which has one solution. via CRT.
B) $x \equiv 0 \mod 1$ and $x \equiv 1 \mod 12$ which has one solution.via CRT.
C) $x \equiv 0 \mod 3$ and $x \equiv 1 \mod 4$ which has one solution.via CRT.
D) $x \equiv 0 \mod 4$ and $x \equiv 1 \mod 3$ which has one solution. via CRT.
The solution to A) is $x= 0$, B) is $x =1$, C) $x = 9$ D)$ x = 4$
Example 2
Solve $\ x^2 = x \mod 360$.
$360 \equiv 8 \times 9 \times 5$ so there will be 8 solutions:
$ (x \equiv 0 \mod 360) \rightarrow x = 0$
$ (x \equiv 1 \mod 360) \rightarrow x = 1$
$ (x \equiv 0 \mod 8) \  AND \ \  (x \equiv 1\mod 45) \rightarrow x = 136$
$ (x \equiv 0 \mod 45) \  AND \ \  (x \equiv 1 \mod 8) \rightarrow x = 225$
$ (x \equiv 0 \mod 9) \  AND \ \  (x \equiv 1 \mod 40) \rightarrow x = 81$
$ (x \equiv 0 \mod 40) \  AND \ \  (x \equiv 1 \mod 9) \rightarrow x = 280$
$ (x \equiv 0 \mod 5) \  AND \ \  (x \equiv 1 \mod 72) \rightarrow x = 145$
$ (x \equiv 0 \mod 72) \  AND \ \  (x \equiv 1 \mod 5) \rightarrow x = 216$.
Which would have been practically impossible by trial and error.
