one king-2 leg
five wives-10 legs
each wife has five room, so total no. of rooms=25 rooms
In each room there are five big cats= 25*5=125 cats ,means 125*4=500 legs
Each big cat has 5 small cats=125*5=625 small cats ,means 625*4=2500 legs
so total no. of legs in this palace = 2+10+500+2500 =3012 legs