I'm looking for fast a way to compute n mod x1
, n mod x2
, n mod x3
, ... I found a an article about "remainder trees" which claims to do just that.
However, I fail to see how is the above approach any better than naively computing each mod
separately (even the last step of the above remaindersusingproducttree
seems to doing exactly this). I also trivially benchmarked the above code and it does not seem to run faster.
My question is, I guess "remainder trees" somehow work better than the naive approach but I don't understand how. Please, could anyone shed some light into this?
Alternatively, is there any other way to quickly computing the many mod
operations?