For a point or ball, the formula is F=A/r^2
For a complicated shape, the formula is (something like[1]) F=A/r^2+B/r^3+C/r^4+... , where r is the distance to the "center" (and some parts are closer and some parts are more far away).
An important property of magnets is that A=0, so the r^2 term dissapears. And in many cases it can be simplified to F=B/r^3 [1, again].
[1] The complete formula considers also the directions, so it's longer
https://en.wikipedia.org/wiki/Multipole_expansion