Stuck with this differential equation question, not getting the correct answer. Suppose that, in order to buy a house, you obtain a mortgage. If the lender advertises an annual interest rate $r$, your debt $D$ will increase exponentially according to the simple O.D.E.
$$\frac{dD}{dt}=rD.$$
If you pay your debt at a rate of $P$ (continuous annual rate), the evolution of your debt will then (under assumptions of continual compounding and payment) obey the linear differential equation
$$\frac{dD}{dt}=rD−P.$$
Using this model, answer the following question: 

If initial amount of the mortgage is for $400,000$, the annual interest rate is $5\%$ , and you pay at a rate of $40,000$ every year, how many years will it take you to pay off the debt? 

 A: The first differential equation:
$$\frac{\mathrm{d}D}{\mathrm{d}t}=rD$$
$$\frac{\mathrm{d}D}{\mathrm{d}t}-rD=0$$
Let's define $\mu(t):=\exp\left(\int -r \mathrm{d}t\right)=\exp(-rt)$, and multiply both sides with it:
$$\exp(-rt)\frac{\mathrm{d}D}{\mathrm{d}t}-\exp(-rt)rD=0$$
By the product rule: $(f\cdot g)'=f' \cdot g+f\cdot g'$, we can see that the LHS can be written as:
$$\frac{\mathrm{d}}{\mathrm{d}t}\bigg(D \exp(-rt) \bigg)=0$$
Now we can integrate both sides with respect to $t$ to get:
$$D \exp(-rt)=C$$
$$D(t)=C\exp(rt)$$
The second one:
$$\frac{\mathrm{d}D}{\mathrm{d}t}=rD-P$$
$$\frac{\mathrm{d}D}{\mathrm{d}t}-rD=-P$$
Define the $\mu(t)$ the same way as before, and multiple both sides with it. Now the LHS will be again the derivate ot $D \mu(t)$:
$$\frac{\mathrm{d}}{\mathrm{d}t}\bigg(D \exp(-rt) \bigg)=-P\exp(-rt)$$
Integrate both sides with respect to $t$:
$$D \exp(-rt)=\frac{-P}{-r}\exp(-rt)+C$$
$$D(t)=\frac{P}{r}+C\exp(rt)$$
We know that $P=40000$, $r=\frac{5}{100}$, and the $D$ at $t=0$ is $400000$. So we can calculate the $C$:
$$400000=\frac{40000}{0.05}+C\exp(0 \cdot 0.05)$$
$$400000=800000+C$$
$$C=-400000$$
So the particular solution for your case:
$$D(t)=-400000e^{0.05t}+800000$$
We want to calculate the time required for $D$ to be $0$:
$$0=-400000e^{0.05t}+800000$$
$$400000e^{0.05t}=800000$$
$$e^{0.05t}=2$$
$$0.05t=\log(2)$$
$$t=20 \log(2)$$
So it will take 14 years.
A: The equation is separable.
$$dt=\frac{dD}{rD-P}.$$
Then by integration,
$$t=\frac1r\log\left|\frac{rD_t-P}{rD_0-P}\right|$$ and it suffices to set $D_t=0$.
