VandanRogheliya's blog

By VandanRogheliya, history, 4 years ago, In English

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?

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

»
4 years ago, # |
  Vote: I like it 0 Vote: I do not like it

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.