$$E_1 = \dfrac{GM_1}{R_1^2}$$ and $$E_2 = \dfrac{GM_2}{R_2^2}$$
In a solid sphere, the gravitational field varies linearly from the center to the surface and is proportional to $$R^{-2}$$ outside the sphere.
From the figure, we have $$E_1 = 2$$ at the surface of the first spher and $$E_2 = 3$$ at the surface of the second sphere.
$$\therefore 2 = \dfrac{GM_1}{R_1^2} = \dfrac{GM_1}{1}, \, GM_1 = 2$$ ...(i)
$$\therefore 3 = \dfrac{GM_2}{R_2^2} = \dfrac{GM_2}{2^2}, \, GM_2 = 12$$ ...(ii)
Dividing (i) by (ii),
$$\dfrac{M_1}{M_2} = \dfrac{2}{12} = \dfrac{1}{16}$$