apoorv_01's blog

By apoorv_01, history, 5 years ago, In English

Hi! Can someone help me debug my code for this problem 431-C

I think I am making some mistake with the modulo (10^9+7)

Here is my code

Thanks!

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

| Write comment?
»
5 years ago, # |
  Vote: I like it +12 Vote: I do not like it

One of the bugs can be on the last line in main() where you are subtracting two numbers which are % MOD. It can go negative. Do it in this way: (a — b + MOD) % MOD

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

    Thanks! that was the exact problem. Still can you explain why we exactly do that(a-b+MOD)%MOD I now get it that a-b can be negative but still can't understand why we exactly add MOD to a-b (won't adding affect our answer ?)