ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1309. Dispute

A question...
Posted by Alexey 27 Jun 2006 15:46
g(x,y)=((y-1)*x^5+x^3+3*x-x*y+7*y) mod M
The result is in 0..M-1
But while counting it I have problems with type.
How to make it work with big values (For expample, If x=1000000)?

Thanks.
Re: A question...
Posted by Sid 27 Jun 2006 17:35
Everybody knows...
x*x mod m = ((x mod m) * (x mod m))mod m
x+x mod m = ((x mod m) + (x mod m))mod m
Yeah, but...
Posted by Alexey 27 Jun 2006 17:58
You mean that
((y-1)*x^5) mod M=(((y-1) mod M)*(x mod M)^5) mod M.
But x mod M can be 9972 (M=9973) and
9972^5 has 14 digits. It's too much.
I know another formula...
(x^y) mod M=((((x mod M)*x) mod M)*x) Mod M... y times.
But it gets incorrect answer...

Can U give me answers for these tests?
1) 9973
2) 19946
3) 29919
4) 8

Thanks.

Edited by author 27.06.2006 18:49