Answer
a) By a factor of 2.
b) Remains constant.
Work Step by Step
a) Let's assume that nitrogen gas is an ideal gas.
We know that the mass of this gas is constant since it is sealed inside the container.
So its initial density is given by
$$\rho_i=\dfrac{m}{V_i}$$
And its initial density after the piston compressed it to half the initial volume is given by
$$\rho_f=\dfrac{m}{V_f}$$
where $V_2=\frac{1}{2}V_i$
Thus,
$$\rho_f=\dfrac{2m}{V_i}=2\rho_i$$
Hence, the mass density of the gas changed, it is now twice the initial density. IT changed by a factor of 2.
---
b) Since the gas is sealed, the number of atoms is constant, and hence the number of moles also remains constant.