The binding energy can be calculated from the work needed to take shells of matter away from the star to infinity, until it's all gone (technically the negative of that).
If $\rho$ is the density, the radius of the star that's left is $r$ then the mass of the star that is left is $\frac{4}{3}\pi r^3\rho$, and the work needed to remove a shell of mass $4\pi r^2 \rho dr$ from $r$ to infinity is
$$G( \frac{4}{3}\pi r^3\rho)\times (4 \pi r^2 \rho) \times \frac{1}{r} dr$$
integrate this from $0$ to $R$ and use $M=\frac{4}{3}\pi R^3\rho$ and you should get the result.
$f$ would have to be larger if the density increases towards the middle as follows:
Imagine an extreme case where almost no matter was at the edge of the star, but nearly all within $\frac{R}{2}$ - it's like having a star of the same mass, but half the radius, so $-f\frac{GM^2}{R}$ changes to $-f\frac{GM^2}{R/2}$ or $-2f\frac{GM^2}{R}$, so it's as if the $f$ has increased.