$\textbf{Question}$: Let $n$ be a positive integer. Determine, in terms of $n$, the number of $x$ where $x \in {1,2,\ldots,n}$ for which $x^2 ≡ x \pmod n.$
$\textbf{My solution}$: Let $n=p_1^{a_1}p_2^{a_2}\cdots p_k^{a_k}$. Now for each of the prime power we have two choices :
$p_i^{a_i} \mid x$, $\; $or,
$p_i^{a_i} \mid x-1$.
Then Chinese Remainder Theorem would make sure that these $n$ congruences result in one unique $x.$
Hence, our answer is $2^{\omega(n)}$ where $\omega(n)$ denotes the number of distinct prime factors of n.
I wanted to verify my answer and I would also appreciate any kind of remark.