When the mass is same, the number of atoms is inversely proportional to the molecular mass. This means less will be the molecular mass, more will be the number of atoms.
H2O = 2× 1 + 16 = 18u
O2 = 2× 16 = 32u
CO2 = 12 × 2 × 16 = 44u
CH4 = 12 + 4× 1 = 16u
Hence, 18 g of CH4 has maximum numbers of atoms.