I try to solve some simple algorithmic task and I got problem with modulo operation.
I need to calc this kind of operation:
(100003 - 200003*x + 300007*x*x*x) % 1000000
Of course both 300007*x*x*x
and 200003*x
can easily overflow that 1000000 so I neeed to 'make' modulo on all parts.
I have found sth like this: Sum and multiplication modulo And tried to "do a mod P after every step." like this:
res = 100003
res = (100003 - 200003*x) % 1000000) % 1000000
...
Is that correct? Couse I haven't got right result.