Yearly contribution to reach given stock (compound interest) I'm working on a calculator to compute the final stock given a yearly contribution (either a fixed contribution or with a linear growth). The user provides the contribution for the first year, if he wants to increase this contribution yearly (the growth value is fixed, the user only chooses if he wants it or not), the interest rate and the number of years (compounding frequency is always yearly).

Calculate the final stock given those imputs isn't difficult, I simply use the Compound Interest formula for each year from $zero$ to $t$ and accumulate the results:
$$F = Py(1+i)^t$$
Where:

$F =$ Final value

$Py =$ Contribution on year $y$ (same each year or increased by a percentage)

$i =$ Interest rate

$t =$ Remaining years

But I don't have a clue about how to calculate (or at least approximate) the other way around. I.e. calculate the needed yearly contribution to reach a desired final stock, given the interest rate and the number of years, either with fixed contributions or increasing ones.
Let g be the (constant) growth rate and  $G=1+g$ the growth factor. And let r be the interest rate and $q=1+r$. Then the future value of the growing contributions  is

$F_n=C\cdot  q^{n-1}+ C\cdot q^{n-2}\cdot G+\ldots + C\cdot q\cdot G^{n-2}+C\cdot  G^{n-1}$

$C\cdot  q^{n-1}:$ The first contribution has to be compounded n-1 times and no growth.

$C\cdot  G^{n-1}:$ The n-th contribution has grown n-1 times and no compounding.

$F_n=C\cdot \left[  q^{n-1}+  q^{n-2}\cdot G+\ldots + q\cdot G^{n-2}+  G^{n-1} \right]$

$q\cdot F_n=C\cdot \left[  q^{n}+  q^{n-1}\cdot G+\ldots + q^2\cdot G^{n-2}+ q \cdot G^{n-1} \right] \quad \quad \quad (1)$

$G\cdot F_n=C\cdot \left[ \ \ \quad  q^{n-1}\cdot G+  q^{n-2}\cdot G^2+\ldots + q\cdot G^{n-1}+  G^{n} \right] \quad (2)$

Substracting (2) from (1)

$(q-G)\cdot F_n=C\cdot (q^n-G^n)$

$\boxed{F_n=C\cdot\frac{q^n-G^n}{q-G}}$
Your formula is $\sum_{t=0}^n P_y(1+ i)^t$.  That is the same as the "geometric sum" $\sum_{t= 0}^n ar^t$ for which a formula is known:  $\frac{a(1- r^{n+1}}{1- r}$.    Here $a= P_y$ and r= 1+ I so that becomes
$F=\frac{P_y(1- (1+ i)^n)}{i}$.  So $P_y= \frac{Pi}{1- (1+i)^{n+1}}$