I found an identity which takes most of the work out of finding the solution. This may be written as
(1) t (a, b) = Sum (for k =0 to b-1) Floor[ k a / b] = (a b - a - b + GCD(a, b)) / 2
This means that the problem may be written as
(2) s (a, b, m) = t (a, b) + Sum (for k =b to m) Floor[ k a / b]
We can improve the efficiency of this by letting r = Floor [ (m+1) / b] so (2) becomes
(3) s (a, b, m) = t (r a, r b) + Sum (for k =r b to m) Floor[ k a / b]
Finally we minimise the residual calculation by ensuring that (a, b) = (a / GCD(a, b), b / GCD(a, b))
Edited on December 29, 2005, 6:44 pm
Edited on December 29, 2005, 7:03 pm
|
Posted by goFish
on 2005-12-29 18:38:06 |