Блог пользователя apoorv_01

Автор apoorv_01, история, 4 года назад, По-английски

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!

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +12 Проголосовать: не нравится

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

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +12 Проголосовать: не нравится

    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 ?)