Блог пользователя Cooper1214

Автор Cooper1214, история, 2 года назад, По-английски

So, I have encountered a strange problem while solving 1541B — Pleasent Pairs
My first solution gets accepted ( Solution 1 ) , while the second one got TLE ( Solution 2).

I don't understand why this is happening. They both are almost same. Any help?
Thank you.

  • Проголосовать: нравится
  • +4
  • Проголосовать: не нравится

»
2 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

This happens because an overflow of i*j expression (i * j can be 4*10^10 that more than can be placed in int (2^31-1 (2'147'483'647) is the max int value) ) so the cycle doesn't end when i*j > 2*n and you get TLE. You just can write 1LL*i*j > 2*n and this will get accepted.