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

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

I was trying to solve this question.

First I wrote this solution which got WA.

Then after checking other already AC solutions I changed the solution to this which got AC.

Both solutions look mathematically identical to me.

Can anyone please explain to me where I am wrong?

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

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

In the first submission, there might be an overflow while multiplying (b - 1) * g / n (or m) and (d - 1) * g / n (or m) but this isn't flagged as a runtime error as it is only an RTE case for signed numbers (you are using unsigned numbers). In your second submission, you essentially do the same thing but pre-dividing n and m won't cause overflow.