Let A be a n×n diagonal matrix with characteristic polynomial
(x−c1)d1(x−c2)d2…(x−ck)dk,
where c1,c2,…,ck are distinct (which means that c1 appears d1 times on the diagonal, c2 appears d2 times on the diagonal, etc. and d1+d2+⋯+dk=n).
Let V be the space of all n×n matrices B such that AB=BA. Prove that the dimension of V is
d12+d22+⋯+dk2.