No, 0.5 mole of magnesium (Mg) atoms and 0.5 mole of oxygen (O2) gas do not have the same number of atoms.
Avogadro's number, denoted by 6.022 x 10^23, represents the number of entities (atoms, molecules, or formula units) in one mole of a substance.
In 0.5 mole of Mg atoms, there would be 0.5 x (6.022 x 10^23) = 3.011 x 10^23 magnesium atoms.
In 0.5 mole of oxygen gas (O2), there would be 0.5 x (6.022 x 10^23) = 3.011 x 10^23 oxygen molecules.
Since each oxygen molecule (O2) consists of two oxygen atoms, the total number of oxygen atoms in 0.5 mole of oxygen gas is twice the number of oxygen molecules. Therefore, 0.5 mole of oxygen gas contains 2 x 3.011 x 10^23 = 6.022 x 10^23 oxygen atoms.
Hence, 0.5 mole of magnesium atoms (3.011 x 10^23 atoms) and 0.5 mole of oxygen gas (6.022 x 10^23 atoms) have a different number of atoms.