873  Loan (II)
Moderator: Board moderators
873  Loan (II)
can somebody tell me how can I calculate the output of the program
I only need the formula, nothing else.
I just can't seem to find the formula
HEELPPPPPPP
I only need the formula, nothing else.
I just can't seem to find the formula
HEELPPPPPPP

 New poster
 Posts: 1
 Joined: Thu Jun 16, 2005 5:52 pm
about the output format...
Hi there,
I tried to submit the Code (C++) for problem 873 and the compilation worked well, but then i got a "wrong answer".
I know that my results are right so it has to be something with the output format which is causing the error.
Now my questions:
Should my Output come with a leading blank line and or a blank line at the end?
What Output should I have if the numbers of cases are 0 or negative? None? Blank line?
And as I am a newbie to c++ could you tell me if my Code (just in/output) is wrong? It works fine using the console, but I actually don't know how the input comes from the judge or how he is reading the output...
PS: It really would have helped if the code samples postet in "HOWTOs" would have worked...
I tried to submit the Code (C++) for problem 873 and the compilation worked well, but then i got a "wrong answer".
I know that my results are right so it has to be something with the output format which is causing the error.
Now my questions:
Should my Output come with a leading blank line and or a blank line at the end?
What Output should I have if the numbers of cases are 0 or negative? None? Blank line?
And as I am a newbie to c++ could you tell me if my Code (just in/output) is wrong? It works fine using the console, but I actually don't know how the input comes from the judge or how he is reading the output...
Code: Select all
#include <iostream>
#include <vector>
using namespace std;
int main () {
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
int cases = 0;
cin >> cases;
if (cases <= 0) {
return 0;
}
int initial;
int percentage;
int months;
vector<float> result(cases);
for (int i=0;i<cases;i++) {
cin >> initial >> percentage >> months;
result[i] = monthly(initial, percentage, months);
}
if (cases == 1) {
cout << result[cases1];
return 0;
}
for (int i = 0; i < cases1; i++) {
cout << result[i] << endl << endl;
}
cout << result[cases1];
return 0;
}

 A great helper
 Posts: 481
 Joined: Sun Jun 19, 2005 1:18 am
 Location: European Union (Slovak Republic)
Re: about the output format...
You should write endl ("\n") after every line.luckybigpack wrote:Should my Output come with a leading blank line and or a blank line at the end?
Code: Select all
cout << result[cases1] << endl;
Hi,
You can find the formula at
http://mathforum.org/dr.math/faq/faq.interest.html
Then scroll down to the topic titled
"Installment Loans"
You can find the formula at
http://mathforum.org/dr.math/faq/faq.interest.html
Then scroll down to the topic titled
"Installment Loans"

 Experienced poster
 Posts: 131
 Joined: Sat Jul 17, 2004 4:09 am
 Location: Lima, Per
There is a O(1) formula, and it's very easy to derive:
Let a_i be the amount of money you owe the bank at the end of ith month, a_0 = initial capital, Y = yearly interest, and P be the monthly payment.
Clearly, a_i = a_{i1} + Y/12 a_{i1}  P.
You can write this recurrence in the form: a_i = r a_{i1}  P, where r = 1 + Y/12.
First few elements of {a_i} are:
a_1 = r a_0  P
a_2 = r^2 a_0  r P  P
a_3 = r^3 a_0  r^2 P  r P  P
a_4 = r^4 a_0  r^3 P  r^2 P  r P  P
...
a_n = r^n a_0  P(1 + r + r^2 + ... + r^(n1))
The sum in brackets is a geometric series, so it simplifies to:
a_n = r^n a_0  P (r^n  1) / (r  1)
Knowing that a_n = 0, you can solve for P in the last equation and that's all.
Let a_i be the amount of money you owe the bank at the end of ith month, a_0 = initial capital, Y = yearly interest, and P be the monthly payment.
Clearly, a_i = a_{i1} + Y/12 a_{i1}  P.
You can write this recurrence in the form: a_i = r a_{i1}  P, where r = 1 + Y/12.
First few elements of {a_i} are:
a_1 = r a_0  P
a_2 = r^2 a_0  r P  P
a_3 = r^3 a_0  r^2 P  r P  P
a_4 = r^4 a_0  r^3 P  r^2 P  r P  P
...
a_n = r^n a_0  P(1 + r + r^2 + ... + r^(n1))
The sum in brackets is a geometric series, so it simplifies to:
a_n = r^n a_0  P (r^n  1) / (r  1)
Knowing that a_n = 0, you can solve for P in the last equation and that's all.

 Experienced poster
 Posts: 131
 Joined: Sat Jul 17, 2004 4:09 am
 Location: Lima, Per

 Guru
 Posts: 647
 Joined: Wed Jun 26, 2002 10:12 pm
 Location: Hong Kong and New York City
 Contact:
I use bisection and get WA.. is there any I/O?
I run the bisect 200 times, so it should be precise enough..
I run the bisect 200 times, so it should be precise enough..
Check out http://www.algorithmist.com !