After k payments, the amount A still owed is
A = P(1+[i/q])k - Mq([1+(i/q)]k-1)/i, = (P-Mq/i)(1+[i/q])k + Mq/i. The amount of the fixed payment is determined byM = Pi/[q(1-[1+(i/q)]-nq)]. The amount of principal that can be paid off in n years isP = M(1-[1+(i/q)]-nq)q/i. The number of years needed to pay off the loan isn = -log(1-[Pi/(Mq)])/(q log[1+(i/q)]). The total amount paid by the borrower is Mnq, and the total amount of interest paid isI = Mnq - P.