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.
This happens because an overflow of
i*j
expression (i * j
can be4*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 wheni*j > 2*n
and you get TLE. You just can write1LL*i*j > 2*n
and this will get accepted.Wow. I didn't noticed that. Thank you. :)