When purchasing a new home, the purchasers often take out a loan to pay for it. In this problem, we will be considering loans with the following terms:
- At the beginning of each month, the purchasers pay a fixed amount towards settling the loan, which decreases the amount they owe.
- At the end of the month, the amount the purchasers owe increases due to interest. Each month, 1/12 of the annual interest rate is added to the amount owed. Hence, if the annual interest rate is 12%, then the debt increases by 1% each month. You may assume that the amount owed after adding interest is always rounded up to the nearest dollar greater than or equal to the actual value.
Your task is, given the annual **interest** rate in tenths of a percent, the original amount of the **loan**, and the period over which the loan is to be repaid, calculate the minimum integral monthly payment so that the loan is repaid in **term** years or less. All monetary units are in dollars.
For example, if **loan** = 1000, **interest** = 50, and **term** = 1, then the loan is for $1000, to be paid back in one year, at an annual interest rate of 5%, or (5/12)% per month. If the purchasers pay back $86 every month, then the total amount owed will be as follows after each month:
month | after making payment | after interest accrues
------+----------------------+------------------------------------
1 | 1000 - 86 = 914 | ceiling(914 * (1 + 5/12/100)) = 918
2 | 918 - 86 = 832 | ceiling(832 * (1 + 5/12/100)) = 836
3 | 836 - 86 = 750 | 754
4 | 754 - 86 = 668 | 671
5 | 671 - 86 = 585 | 588
6 | 588 - 86 = 502 | 505
7 | 505 - 86 = 419 | 421
8 | 421 - 86 = 335 | 337
9 | 337 - 86 = 251 | 253
10 | 253 - 86 = 167 | 168
11 | 168 - 86 = 82 | 83
12 | 86 is more than enough to pay off the rest
Clearly, 85 a month wouldn't be enough, since we just barely paid off the loan at 86. |