Getting TLE error

what is difference between for (int i=1;i<=sqrt(y);i++) and for(int i=1;ii<=y;i++)?
When I am using this i
i<=y .I am getting TLE Error.Can anyone Explain me?

1 Like

It’s the same. You are facing TLE Error because of integer overflow.
For eg: If y = 10^12, so when loop variable(i) will reach 10^5 or more then it will compute i*i which will be 10^10 and since it is larger than 2^31-1, it will cause overflow.
Replace int i=1 with long long int i=1, and you will be fine.

1 Like

Ya ya got it…Thanks a lot…

1 Like