Step 1: The decay law.
The amount left after time $t$ is \[ N(t) = N_0\left(\frac{1}{2}\right)^{t/T_{1/2}}, \] where $T_{1/2}$ is the half-life.
Step 2: Write each material's amount.
For $A_1$ with half-life $20\,\text{s}$ and start $40\,\text{g}$: $N_1 = 40\left(\tfrac{1}{2}\right)^{t/20}$. For $A_2$ with half-life $10\,\text{s}$ and start $160\,\text{g}$: $N_2 = 160\left(\tfrac{1}{2}\right)^{t/10}$.
Step 3: Set them equal.
We want $N_1 = N_2$: \[ 40\left(\tfrac{1}{2}\right)^{t/20} = 160\left(\tfrac{1}{2}\right)^{t/10}. \]
Step 4: Tidy up the equation.
Divide both sides to collect the powers of one half: \[ \frac{(1/2)^{t/20}}{(1/2)^{t/10}} = \frac{160}{40} = 4. \] The left side is $(1/2)^{t/20 - t/10} = (1/2)^{-t/20} = 2^{t/20}$.
Step 5: Solve for $t$.
So $2^{t/20} = 4 = 2^2$, giving $\frac{t}{20} = 2$ and \[ t = 40\ \text{s}. \]
Step 6: Conclusion.
The two amounts become equal after $40\,\text{s}$. \[ \boxed{40\ \text{s}} \]