I remember having solved this question a few years back in a very elegant way, it's from GATE 2012.
A is given to be a radial vector (radially outward from origin) with it's magnitude $|A| = kr^n$. So if $\vec r = x \hat i + y \hat j + z \hat k$ then $\vec r . \vec r = ||r|| = x^2 + y^2 + z^2$.
We need to find $n$ such that $\nabla . A = 0$.

Ok below is how I remember solving it.

$$\nabla A = kn r^{n-1} |r| + kr^n 2r = knr^n (n+2)$$
So we get the answer $n = -2$.
By going to the spherical coordinate system, I observed that the vector is completely along $\hat e_r$. So the gradiant can be written as a partial derivative w.r.t r after a dot product with the unit r vector.
But I'm not clear about if I can keep the norm of $r$ seperate from $r^{n-1}$. If I am being correct, I'm getting $n = -1$ as the answer. Also won't $\hat e_r . \hat e_r = 1$, since we write $A= |A|\hat e_r$.

So my question is how can I solve this in an elegant manner. Is the answer $-2$? Is my proof salvageable?