Answer
The ionic compound formed would have the chemical formula $$Mg_3N_2$$
Work Step by Step
The electron configuration of $Mg$ is $$[Ne]3s^2$$
The electron configuration of $N$ is $$1s^22s^22p^3$$
Both of these atoms would tend to lose, gain or share electrons so that it could reach an octet, that is to have 8 valence electrons, or in other words, to achieve the configuration of a noble gas.
$N$ atom lacks 3 more electrons to reach an octet $(2s^22p^6)$, while $Mg$ atom, if loses 2 valence electrons in subshell $3s$, would achieve the configuration of noble gas $Ne$, with 8 valence electrons (an octet).
The problem now is just like part c). The number of electrons given and gained are not equal, and adding another atom does not solve the problem.
So again, if there are 3 $Mg$ atoms involved that are willing to lose 6 electrons in total, and 2 $N$ atoms involved that are willing to accept 6 electrons in total, then every atom is satisfied.
Eventually, there is 3 $Mg$ atoms and 2 $N$ atoms involved in the reaction. That means the ionic compound formed would have the chemical formula $$Mg_3N_2$$