There are two ways to work this out, one is a lot simpler than the other, I will post the simpler method here.
The relative formula mass of magnesium oxide, MgO (40), is just a sum of the mass of magnesium (24) and the mass of oxygen (16).
24 + 16 = 40
We are told that 24 g of Mg produces 40 g of MgO when it reacts with 16 g of oxygen. We only need 10 g of MgO, 1 quarter of that given in the question.
In order to produce 10 g of MgO, we therefore only need a quarter of what we needed to make 40 g of MgO.
So, we would only need 24 g / 4 = 6 g of Mg to produce 10 g of MgO.