If $A$ is a $n\times n$ matrix that satisfies $A^2=A$, then prove that $\operatorname{rank}(A)+\operatorname{rank}(I-A)=n$ [closed]

Note that $A^{2} = A \Rightarrow A - A^{2} = (I - A)A = 0$. For $v \in \mathbb{R}^{n}$, we have $(I - A)Av = (I - A)(Av) = 0 \Rightarrow Av \in \text{ker}(I - A) \Rightarrow \text{im}(A) \subseteq \text{ker}(I - A)$. Next, suppose $v \in \text{ker}(I - A)$. Then $(I - A)v = 0 \Rightarrow v = Av \in \text{im}(A) \Rightarrow \text{ker}(I - A) \subseteq \text{im}(A)$. Thus, $\text{im}(A) = \text{ker}(I - A)$.

By the rank-nullity theorem,

$$n = \text{dim}(\text{ker}(I - A)) + \text{rank}(I - A) = \text{rank}(A) + \text{rank}(I - A)$$