Question: what is the formula to calculate the total cost of a loan?
Answer: The formula you require is the standard one for calculating the time to repay. With larger repayments the time to completely repay the loan is reduced. The total cost of the loan is then n * d .