Array ( [0] => [1] => questions [2] => Basic [3] => Saving-for-a-rainy-day ) Codevita Previous Questions | Saving for a rainy day | THE INQUISITIVE





Saving for a rainy day

LEVEL:Beginner

Description

By nature, an average Indian believes in saving money. Some reports suggest that an average Indian manages to save approximately 30+% of his salary. Dhaniram is one such hard working fellow. With a view of future expenses, Dhaniram resolves to save a certain amount in order to meet his cash flow demands in the future.
Consider the following example.
Dhaniram wants to buy a TV. He needs to pay Rs 2000/- per month for 12 installments to own the TV. If let's say he gets 4% interest per annum on his savings bank account, then Dhaniram will need to deposit a certain amount in the bank today, such that he is able to withdraw Rs 2000/- per month for the next 12 months without requiring any additional deposits throughout.
Your task is to find out how much Dhaniram should deposit today so that he gets assured cash flows for a fixed period in the future, given the rate of interest at which his money will grow during this period.

Input Format

First line contains desired cash flow M
Second line contains period in months denoted by T
Third line contains rate per annum R expressed in percentage at which deposited amount will grow
Constraints:
M > 0
T > 0
R >= 0
Calculation should be done upto 11-digit precision

Output Format

Print total amount of money to be deposited now rounded off to the nearest integer.


Example 1:

Input
500
3
12
Output
1470
Example 2:

Input
6000
3
5.9
Output
17824
Example 3:

Input
500
2
0
Output
1000

oops

Login to see Discussion




Approach

To get the question correctly lets take the first example which is
500 3 12
output is 1470

for first month: 1470 * (1/12) * (12/100) = 14.7 rounded to 15
1470 + 15 = 1485

above we have added 12/100 because for a year there are 12 months and percentage is calculated per 100 so 12/100 and we have 1/12 because 12 percent is calculated per year , then for one month it would be 1/12 of 12 percent which is (1/12) * (12/100)

after first month withdrawal 1485-500 = 985

for second month: 985 * (1/12) * (12/100) = 9.85 rounded to 10
985+10 = 995

after second month withdrawal 995 - 500 = 495
for third month 495*(1/12)*(12*100) = 4.95 rounded to 5
495+5 = 500
which is sufficient for the third month withdrawal

required amount = present amount + present amount * (interest %/ deposited period)

deposited period = 1/12 (for calculating the interest gained for per month)

interest % = interest/100

present amount = required amount/(1 + interest % / deposited period )

present amount = required amount/ (1 + interest % / 1200)

to find interest amount from present amount

interest = required amount- present amount

required amount = required amount + ( monthly pay- interest)


so our final logic will be

repeat month time {

present amount = required amount / (1+interest% / 12)
interest = required amount- present amount
required amount = required amount -(monthly pay-interest)

}


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution