In order to calculate the number of atoms, we must first know the number of moles present. And
moles = (mass present) / (molecular mass)
Therefore, the moles of Mg present are
170 / 24 = 7.08
The number of atoms in a mole of substance is given by Avagadro's Number which is 6.02 x 10^23
Since there are 7.08 moles, there are:
7.08 * 6.02*10^23
= 4.26 * 10^24 atoms