I'm still confused, but based on Magic_fubu's interpretation:
round(if(r - (n * 0.3) < 0.51, 20 * (sqrt(sqrt(n) * n / r)) + 20, 20))
I think that's right. Magic_fubu had the gist of it right, but just missed a couple of parentheses. That "+ 20" in the original formula was in the wrong place, too, I believe. Regardless, this appears to match the grid you supplied.