I have starting value $X$. I need sum $X$ with $X\cdot Y$ from previous result $Z$ times. So it will require :
$ X + [X + XY] + [X + (X + XY)Y] + [X + (X + (X + XY)Y)Y] + \dots - Z $
iterations.
How do you find formula?
I would start with:
$$ ... = X + X[1 + Y] + X[1 + (1 + Y)Y] + ... = X(1 + [1 + Y] + [1 + Y + Y^2] + ...) = X(Z + (Z - 1)Y + (Z - 2)Y^2 + ... + Y^(Z - 1)) = ?$$
Take this sum $$ s = 1 + (1 + a) + (1 + a + a^2) + \ldots (1+a+ \ldots + a^{n-1}) \\ = \frac{1-a}{1-a}+\frac{1-a^2}{1-a} + \frac{1-a^3}{1-a}+ \ldots + \frac{1-a^n}{1-a} \\ = \frac{n - a\frac{1-a^n}{1-a}}{1-a} = \frac{n}{1-a}-a\frac{1-a^n}{(1-a)^2} $$