CALCMON Editorial

PROBLEM LINK:

Practice
Contest

Author: Baban Gain
Editorialist: Baban Gain

DIFFICULTY:

EASY

PREREQUISITES:

High School Mathematics

PROBLEM:

Chef want to get N amount of money from a bank after Y years at R percent compound interest rate.
Chef can deposit Ai amount of money on beginning of ith Year starting from next year ( that is 2nd year )
Calculate the amount of money he need to deposit during 1st year.

EXPLANATION:

First calculate the total amount that would be accumulated after Y years for all the money that chef can deposit on subsequent years.
The amount deposited on last year will get interest for 1 year, amount deposited on second last year will get interest for 2 year and so on.

Total amount accumulated after Y years can be calculated as :
amount_accumulated = 0
For i=0 to Y-2,
            amount_accumulated = amount_accumulated + ( principle[i] * ( (1 + (R/ 100)) ** (Y-i-1) ) )

Now the remaining amount is, remaining = Total amount required - amount_accumulated

So, we need to find such a principle amount that would yield remaining amount after Y year.
By inverting the formula Amount = P * { (1+ (R/100)) }Y
we get,
P = Amount/{ (1+ (R/100)) }Y
where amount = remaining amount.

Now ceil the principle and print it.

Author’s Solution :

Click Here