Conceptually, the way amortization of loan payments works is that the lender should come out even at the end of the loan when you account for future value of money based on the loan's interest rate. If the lender loaned $A$ dollars at an interest rate per period $r$ over $n$ periods, the future value (at the end of the loan) of the money lent is $A(1+r)^n$. If the payment is $p$, then the future value of the first payment is $p(1+r)^{n-1}$ (paid at the end of the first period), for the second is $p(1+r)^{n-2}$, for the $k$th payment is $p(1+r)^{n-k}$, up to the last payment which is paid at the end of the loan so its future value is $p(1+r)^0=p$. If you take the sum of these future values of all the payments, it should be equal to the future value of the original loan. This equation can be solved for $p$ in terms of the general $A$, $r$, and $n$ to get a generalized amortization formula.
Now, on a period-to-period basis, the balance is defined by the initial balance $b_0=A$ and the recurrence relation $b_{k}=(1+r)b_{k-1}-p$. That is, the change from one period to the next is to add the interest due and subtract the payment. Knowing the parameters of the loan and the payment, you can use this to find the balance after a specific number of periods, as well as the breakdown of interest and principal in each payment.
Suppose the initial principal is $A$, and $12,000$ is withdrawn at the end of each year.
At the end of the first year (immediately after the withdrawal), $A(1.05)^1-12,000$ remains.
This grows for another year, and then the second withdrawal is made. At the end of the second year, $A(1.05)^2-12,000(1.05) - 12,000$ remains.
Continuing, one sees that at the end of twenty years, since the balance is zero, we have
$$0 = A(1.05)^{20} - 12,000\left(1 + (1.05)^1+(1.05)^2+\cdots + (1.05)^{19}\right)$$
The geometric sum can be simplified as $\frac{1-1.05^{20}}{1-1.05} = \frac{1.05^{20} - 1}{0.05}$, so that
$$A = 12,000\left(\dfrac{1.05^{20}-1}{0.05}\right)(1.05^{20}) = \boxed{12,000\left(\dfrac{1 - 1.05^{-20}}{0.05}\right) \approx 149,546.52}$$
More generally, if an amount $K$ is withdrawn at the end of each of $N$ years, and the annual interest rate is $r$, the initial principal must be
$$K\left(\dfrac{1 - (1+r)^{-N}}{r}\right)$$
Note: I'm assuming you mean for the effective annual rate to be $5$%? If not, you can convert the continuous compounding rate to an effective annual rate using $1+r = e^{0.05}$ and correct the answer accordingly. I am using effective rate in the general formula.
Best Answer
Let $i=4\%$, $p=5\%$, $n=10$, $C=10000$ and $S=10000$. At the end of the 4th year we have $C(1+i)^4-pK-K=P$ and at the end of the 5th year we have $P(1+i)-pK-K=Q$. At the end of the 6th year we have $Q(1+i)-K=M$ and at the end of 7th year $M(1+i)-K=N$. So the sum $N$ will produce $N(1+i)^{n-7}=S$ at the end of the $n$-th year. That is $$\Big(\underbrace{\{\underbrace{[\underbrace{(\underbrace{C(1+i)^4-(1+p)K}_{P})(1+i)-(1+p)K }_Q](1+i)- K}_M\}(1+i)-K}_N\Big)(1+i)^{n-7}=S\tag 1$$ and after some products
$$\scriptsize \begin{align*} S &=\left(\Big\{\Big[C(1+i)^4(1+i)-(1+p)K(1+i)-(1+p)K\Big](1+i)-K\Big\}(1+i)-K\right)(1+i)^{n-7}\\ &=\left(\Big\{C(1+i)^4(1+i)(1+i)-(1+p)K(1+i)(1+i)-(1+p)K(1+i)-K\Big\}(1+i)-K\right)(1+i)^{n-7}\\ &=\left(C(1+i)^4(1+i)(1+i)(1+i)-(1+p)K(1+i)(1+i)(1+i)-(1+p)K(1+i)(1+i)-K(1+i)-K\right)(1+i)^{n-7}\\ &=C(1+i)^4(1+i)(1+i)(1+i)(1+i)^{n-7}-(1+p)K(1+i)(1+i)(1+i)(1+i)^{n-7}-(1+p)K(1+i)(1+i)(1+i)^{n-7}-K(1+i)(1+i)^{n-7}-K(1+i)^{n-7}\\ &=C(1+i)^{4+1+1+1+n-7}-(1+p)K(1+i)^{1+1+1+n-7}-(1+p)K(1+i)^{1+1+n-7}-K(1+i)^{1+n-7}-K(1+i)^{n-7}\\ &=C(1+i)^{n}-(1+p)K(1+i)^{n-4}-(1+p)K(1+i)^{n-5}-K(1+i)^{n-6}-K(1+i)^{n-7}\\ &=C(1+i)^n-(1+p)K\Big[(1+i)^{n-4}+(1+i)^{n-5}\Big]-K\Big[(1+i)^{n-6}+(1+i)^{n-7}\Big] \end{align*} $$
or $$C(1+i)^n-(1+p)K\Big[(1+i)^{n-4}+(1+i)^{n-5}\Big]-K\Big[(1+i)^{n-6}+(1+i)^{n-7}\Big]=S\tag 2$$ and finally $$ K=\frac{C(1+i)^n-S}{(1+p)\left[(1+i)^{n-4}+(1+i)^{n-5}\right]+\left[(1+i)^{n-6}+(1+i)^{n-7}\right]} $$