okay4869's blog

By okay4869, history, 7 months ago, In English

TLE CODE:

https://mirror.codeforces.com/contest/1886/submission/239483379

Accepted Code:

https://mirror.codeforces.com/contest/1886/submission/239483485

Is it because of

ans*=i;ans%md
ans=(ans*i)%md

? If So can anyone explain the reason why one gives TLE but other is fine?

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

»
7 months ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Notice how ans%md does nothing. ans doesn't get reduced modulo md, which causes TLE. You need ans%=md.

  • »
    »
    7 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Oh my god I am so dumb. It works now. Thank you