You want to solve for n from the

A = P[r*(1+r)^n] / [(1+r)^n -1].

Here is one way. The idea is just to isolate n by itself alone on one side of the equation.

Divide both sides by r*P,

A / rP = [(1+r)^n] / [(1+r)^n -1]

Multiply both sides by [(1+r)^n -1],

[A / rP]*[(1+r)^n -1] = (1 +r)^n

Expand,

[A / rP](1+r)^n -[A / Pr] = (1+r)^n

Collect like terms,

[A / Pr](1+r)^n -(1+r)^n = [A / Pr]

(1+r)^n *{[A / Pr] -1} = [A / Pr]

(1+r)^n = [A / Pr] / {[A / Pr] -1}

Take the natural logs of both sides,

n*Ln(1+r) = Ln[A / pr] -Ln{[A / Pr] -1}

Therefore,

n = (Ln[A / Pr] -ln{[A / Pr] -1}) / Ln(1+r)