I try to solve this problem using FOR loop. The code can run successfully on local IDLE( Python 3.4) and give correct answers, but it will raise Memory Error when running on OJ. What is the problem?

```
class Solution:
# @param x, an integer
# @return an integer
def sqrt(self, x):
if x == 0:
return 0
elif x == 1:
return 1
else:
# The following line may raise Memory Error
# The Input is 2147395599
for i in range(int(x/2) + 1):
if (i + 1)*(i + 1) < x:
continue
upper_limit = (i + 1)*(i + 1) - x
lower_limit = x - i*i
if upper_limit > lower_limit:
return i
else:
return i + 1
```