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 thread

Discussion of Problem 1110. Power

Reply to message

  • Messages should be written in English and correspond to the matter of the website.
  • Messages should not contain offences and obscene words.
  • Messages should not contain correct solutions.
Re: what is the difference between this code and that code, still get wrong
Posted by Mahilewets 16 Jul 2017 09:03
Look at the limitations.
You can have X^N=998^998. That is 9,98e1000.
Look at fundamental data types range. double is something like not greater (-1e309;1e309) with 15 digits after point .  That is much smaller than you need.  So,  in function pow there is an overflow.  That means double LOSES PRECISION.  And if actually X^N mod M == Y for some big X^N them your program can't see it.  Because last digits of X^N are lost due to an overflow.

And in netman's code,  there is such a function,  that keeps ONLY the last digits.


JUDGE_ID
Subject