Solution (source code)

= Solution

Substituting $P=\rho/3$ into the continuity equation gives
$$
\dot\rho+4\frac{\dot a}{a}\rho=0,
$$
so
$$
\boxed{\rho=\rho_0a^{-4}}.
$$
Three powers arise from dilution of photon number in physical volume and one from the cosmological redshift of each photon's energy.