rahulpkvij's blog

By rahulpkvij, history, 5 years ago, In English

https://codeforces.me/contest/1265/submission/68128052

Can anyone explain why this code is giving WA on test 6 and how do I correct it ? Thanks in advance.

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Overflow is the cause. In the below line

i*(i-1)*1ll

As the expression is processed from left to right, i*(i-1) is stored in to 'int' first and only then it is multiplied by 1ll. So do 1ll*i*(i-1) to rectify it.