Concept:
Same number of molecules means same number of moles because:
\[
\text{Number of molecules}=nN_A
\]
Step 1: Calculate moles of \(H_2\).
\[
\text{Molar mass of }H_2=2
\]
\[
\text{Moles of }H_2=\frac{5}{2}=2.5
\]
Step 2: Calculate moles of \(CH_4\).
\[
\text{Molar mass of }CH_4=16
\]
\[
\text{Moles of }CH_4=\frac{40}{16}=2.5
\]
Step 3: Since both have:
\[
2.5\ \text{moles}
\]
they have the same number of molecules.
Therefore,
\[
\boxed{5\ \text{g of }H_2\text{ and }40\ \text{g of }CH_4}
\]