I'm not sure whether you meant the cube had a volume of 2cm3 or a side length of 2cm, so I will work out the problem both ways.
Volume = 2cm3
So you need to find the density of a cube with volume(V) = 2cm3 and mass(m) = 500g.
The units of density are mass/volume, so all you need to do is divide the mass by volume.
Density = 500g/2cm3 = 250g/cm3
Side = 2cm
The units of density are mass/volume, so we need to first find the volume of the cube, then divide the mass by the volume.
Volume = length3 = (2cm)3 = 8cm3
Density = 500g/8cm3 = 62.5g/cm3