The first equation is magnesium reaction with oxygen to form magnesium oxide
Mg + O2 ----> MgO
Balance the oxygen of right hand side
Mg+O2 ---> 2 MgO
Now balance the magnesium by putting 2 before magnesium in the LHS side.
2 Mg + O2 ----> 2 MgO
The second equation is
P4 + O2 ----> P2O5
Now balance the P in the RHS
P4 + O2 ----> 2P2O5
Now balance the Oxygen in the LHS
P4 + 5O2 ----> 2 P2O5