• 04-15-2002
neandrake
This is actually for my TI-83+ calculator, but the problem can go to most any language. First, assuming the general equation:
Ax^2+Bx+C=0

and given A, B, and C it is possible to solve for X using the quadratic equations:

(-B + sqrt(b^2-4AC))/(2A)
and
(-B - sqrt(b^2-4AC))/(2A)

to find two answers. However some times there is only one answer and sometimes imaginary numbers. (This isn't my problem however). What I need to accomplish is factoring the equation down not using the quadratic equation. For instance:

X^2 - 4X + 4 = 0

down to:

(X - 2) (X - 2)
which is also
(X - 2)^2

• 04-15-2002
Unregistered
(X + A)*(X + B) == X^2 + 2(A + B) + A * B

You need to write a program to solve for A and B.

I assume you want A and B to be whole numbers, so start by factoring the constant and using those values as hints for A and B.
• 04-15-2002
golfinguy4
I already made one of those. If you want, I can probably email it to you or maybe even post it here.

Edit: You will have to wait till I get back to school because I have it saved there.
• 04-15-2002
neandrake
Ok, but what can I do to get A and B? I'm confused.
• 04-15-2002
neandrake
Could you post it? I forgot to mention that I'm not looking for specific code, but I could probably learn alot from your code.
• 04-15-2002
golfinguy4
To start, make sure that the discriminant is a rational number. Then, use for loops to go through the possible values.
• 04-15-2002
neandrake
How do you calculate possible values?
• 04-15-2002
Unregistered
Factor the constant if you are assuming that everything is a whole number.
• 04-15-2002
neandrake
Huh? I don't understand what you're talking about, Unregistered. Is there some algorithim that solves for multiples of a number?
• 04-15-2002
neandrake
Quote:

Originally posted by Unregistered
(X + A)*(X + B) == X^2 + 2(A + B) + A * B

You need to write a program to solve for A and B.

I assume you want A and B to be whole numbers, so start by factoring the constant and using those values as hints for A and B.

Shouldn't that be:
X^2+2X(A+B) + A*B?
• 04-15-2002
neandrake
wait, is this what happens? Is this true?

(X+ (-b+sqrt(b2-4ac))/(2a)) * (X+ (-b-sqrt(b2-4ac))/(2a)) = X2 + 2X(A+B) + A*B
• 04-15-2002
neandrake
Ax2 + Bx + C = 0
so, two multiples of C must add up to B, (this is for simple purposes, assuming for now that A==1)

ok, here's some pseudo code I came up with:

if B>0 {
for (int j=1;j<=B;j++){
if j * (B-j) == C {
//found a working factor?
}
}
}

is this ok? this is the simplist I've come up with yet, but would it work assuminb B is positive?