TopCoder problem "DepositProfit" used in TCHS SRM 49 (Division I Level One)



Problem Statement

    You've deposited amount dollars into a bank account. The interest rate is annualInterest percent per year, and it is compounded monthly. This means that at the end of each month, the total balance increases by annualInterest/12 percent, and after that the balance is rounded down to the integer number of cents. Return the minimum number of months required to obtain at least profit dollars in profit.
 

Definition

    
Class:DepositProfit
Method:depositTerm
Parameters:int, int, int
Returns:int
Method signature:int depositTerm(int amount, int annualInterest, int profit)
(be sure your method is public)
    
 

Notes

-The monthly interest is calculated as (current deposit amount) * (annual interest rate in percent) / (100*12).
 

Constraints

-amount will be between 10 and 10000, inclusive.
-annualInterest will be between 4 and 24, inclusive.
-profit will be between 1 and amount, inclusive.
 

Examples

0)
    
1000
12
20
Returns: 2
The monthly interest rate is 1%. At the end of the first month, the interest added is 1000*0.01 = 10, for a new total balance of 1010. At the end of the second month, the interest added is 1010*0.01 = 10.10, for a total balance of 1020.10. At this point, the profit is 20.10, which is greater than 20.
1)
    
10
4
10
Returns: 236
2)
    
5000
24
4000
Returns: 30
3)
    
1000
6
5
Returns: 1
The monthly interest rate is 0.5%. At the end of the first month, the interest added is equal to the profit wanted.
4)
    
8238
12
5176
Returns: 49
5)
    
10
4
1
Returns: 34
At the end of the first month, the interest added is approximately 3.33 cents. At the end of the 34-th month, the interest added is approximately 3.67 cents. Both these interests are rounded down to 3 cents.

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=8313

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=10809&pm=8313

Writer:

Nickolas

Testers:

PabloGilberto , Olexiy , ivan_metelsky

Problem categories:

Math