For those who like algebra, we can show that this formula evaluates to 0 for correct inputs:
(x+n)^2 - (f-1) - 2d(n-1) - n^2 = 0
(x+n)^2 - f + 1 - 2dn + 2d - n^2 = 0
-f + 1 + 2d + d^2 = d^2 + 2dn + n^2 - (x+n)^2
(d+1)^2 - f = (d+n)^2 - (x+n)^2
c = (d+n)^2 - (x+n)^2
We end up with the original formula that defines what n and x are.