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?
Notice how
ans%md
does nothing.ans
doesn't get reduced modulomd
, which causes TLE. You needans%=md
.Oh my god I am so dumb. It works now. Thank you