| |
BGonline.org Forums
Exact solution
Posted By: Timothy Chow In Response To: Exact solution (Chuck Bower)
Date: Tuesday, 24 August 2010, at 10:08 p.m.
I'm not sure why you're trying to find clever shortcuts for a slow method.
The method using the polynomial f(x) is easy to program even if you don't have Mathematica as long as your integer variables are large enough to store the numbers in question. You don't need to keep a symbolic "x" around. Just represent a polynomial as an array of coefficients. Multiplying two polynomials f and g is just a nested do-loop:
for n from 0 to 43 do
h[n] = 0
for d from 0 to n do
h[n] = h[n] + f[d]*g[n-d]
end do
end do
To compute f(x)9, you can square f(x) to get f(x)2, square again to get f(x)4, and square a third time to get f(x)8, and finally multiply f(x) by f(x)8. That's four polynomial multiplications. At each stage you need only keep the coefficients up to x43 and you can throw away the higher coefficients because they will never contribute to the final answer you want. All this should take only a few thousand arithmetic operations.
| |
BGonline.org Forums is maintained by Stick with WebBBS 5.12.