<s>[INST] How to show $B^2=B$ when $rank(B) + rank(I_d - B) = d$? I have a question on this specific question from the past entrance examination of a university.
https://www.ism.ac.jp/senkou/kakomon/math_20190820.pdf
Related post: How to calculate eigenvalues of a matrix $A = I_d - a_1a_1^T - a_2a_2^T$
Problem
$≥3$, $_$ is an identity matrix, and $B$ is a d-dimensional square matrix.
Here, how to show $B^2=B$ when $rank(B) + rank(I_d - B) = d$?

Tried
I specifically considered the case of $d = 2$.
In this case, when $rank(B) + rank(I_d - B) = d$, I can find $rank(B) = rank(I_d - B) = 1$
I assume that 


*

*$B = \left[
    \begin{array}{cc}
      a & b \\
      c & d \\
    \end{array}
  \right]
\to \left[
    \begin{array}{cc}
      a & b \\
      0 & d-\frac{c}{a}b \\
    \end{array}
  \right]$

*$I - B = \left[
    \begin{array}{cc}
      1 & 0 \\
      0 & 1 \\
    \end{array}
  \right] - \left[
    \begin{array}{cc}
      a & b \\
      c & d \\
    \end{array}
  \right]
= \left[
    \begin{array}{cc}
      1-a & b \\
      c & 1-d \\
    \end{array}
  \right]
\to \left[
    \begin{array}{cc}
      1-a & b \\
      0 & (1-d)-\frac{c}{(1-a)}b \\
    \end{array}
  \right]$.
From $rank(B) = rank(I-B) = 1$, 


*

*$d - \frac{c}{a}b = 0 \to ad = bc$

*$(1-d)-\frac{c}{(1-a)}b = 0 \to (a+d) = 1$.


And then, 
$
\begin{eqnarray}
B^2 &=& \left[
    \begin{array}{cc}
      a & b \\
      c & d \\
    \end{array}
  \right]\left[
    \begin{array}{cc}
      a & b \\
      c & d \\
    \end{array}
  \right] \\ 
&=& \left[
    \begin{array}{cc}
      a^2 + bc & ab+bd \\
      ac+dc & ad+d^2 \\
    \end{array}
  \right] \\
&=& \left[
    \begin{array}{cc}
      a^2 + ad & ab+bd \\
      ac+dc & ad+d^2 \\
    \end{array}
  \right] \\
&=& \left[
    \begin{array}{cc}
      a(a+d) & b(a+d) \\
      c(a+d) & d(a+d) \\
    \end{array}
  \right] \\ 
&=& \left[
    \begin{array}{cc}
      a & b \\
      c & d \\
    \end{array}
  \right] = B
\end{eqnarray}$
But I don't know how to generalize this.
I guess I can use $A^2 = A$ when $A = I_d - a_1a_1^T - a_2a_2^T$ (link), but I have no idea how to apply it.
 [/INST] Let $B'=I_d-B$. Observe that if $v\in\ker B\cap \ker B'$ then $v=Bv+B'v=0$, hence $\dim(\ker B\cap \ker B')=0$. Thus
$$
\dim(\ker B+\ker B')=\dim \ker B+\dim \ker B'=(d-\textrm{rank} B)+(d-\textrm{rank} B')=d.
$$
On the other hand since $B$ and $B'$ commute, every $v\in \ker B+\ker B'$ satisfies $BB'v=0$. Thus $BB'=0$, as desired.
</s>