okay4869's blog

By okay4869, history, 2 years 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

»
2 years ago, hide # |
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.