This homework is due Thursday, October 2.
The Euclidean algorithm.
59400A + 16200B = d(This is B&W Section 2 problem 2.5 on page NT-25.)
A well written program will do the right thing when the input values are any integers - positive, negative or zero. The only case that might require special treatment is gcd(0,0). There is no right answer then. Just make sure your program doesn't crash.
Note 1. The function that does the computation should not do any printing. That all happens in the calling program. If possible, the calling program should get the integer input values from the command line, or from stdin (System.in in Java). (Of course that's possible. But if your programming skills are so rusty that it's really difficult, don't spend time on it.)
Note 2. Since CS110 is a prerequisite for this course, you should all be able to write this program. But for some of you your programming skills are so rusty that polishing them up so you can answer this question isn't worth the time. If that's the case, don't.
Note 3. It's really easy to find solutions to this problem on the internet. I'd rather you wrote your own, but won't insist. If you do get one from the net you must acknowledge and understand the source and compile and run the program to test it.
I'd still rather your function do no printing, but that's harder to arrange now that there are three integer outputs rather than just one. Do that if you can, but if you can't don't worry.
m = nq + r 0 <= r < n
r
is less than or equal to half of
m
.
Fn
are defined recursively as
F0 = F1 = 1, Fn = Fn-1 + Fn-2The sequence starts 1, 1, 2, 3, 5, 8, 13, 21, ...
F8
and F9
and express it as an integer
combination of those two numbers.
You can also do "long division with remainder" for polynomials with rational coefficients. That is, given polynomials m(x) and n(x) you can find polynomials q(x) and r(x) where r(x) is "strictly smaller than" n(x). Here "strictly smaller than" means "has lower degree than".
Therefore you can carry out the Euclidean algorithm for
polynomials. Do that, to find the polynomial that's the greatest
common divisor d(x)
of
m(x) = x4 + 5x3 + 6x2 -4x - 8and
n(x) = x3 - 3x2 + 4and, at the same time, find polynomials
A(x)
and
B(x)
such that
A(x)m(x) + B(x)n(x) = d(x).
If you're really ambitious you can write your gcd program so that it works for any objects that implement the you-can-do-long-division interface. I don't expect that ...