The balanced equation will be:
6Mg + P(sub 4) -> 2Mg(sub 3)P(sub 2)
On the right side your Magnesium is 2*3 which equals 6, hence the 6 in front of the Magnesium on the left side. Your Phosphorus on the right side is 2*2 which equals 4, so you do not need another number in front of the Phosphorus on the left side. I hope you have a great day and I hope I helped the understanding behind balancing formulas!!