you_know_wh0's blog

By you_know_wh0, history, 3 years ago, In English

i am getting negative value even after applying %M operation at all steps. i dont understand where i'm doing wrong//i wrote this code for C problem of today's contest-codeforces round #711

my code: my code

  • Vote: I like it
  • +3
  • Vote: I do not like it

| Write comment?
»
3 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

x=(x+M)%M; this will convert the negative value in to positive. Prove- x= x%M + M%M then M%M=0 so x=x%M;

  • »
    »
    3 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    yeah, but why i am even getting negative values in the first place. i am computing values in such a way that their range is [0, M].

    • »
      »
      »
      3 years ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      pw can overflow, since it can reach (i-1)^1000 and is never modded.