Here is the first code:

```
class Solution:
# @param {integer} n
# @return {integer}
def countPrimes(self,n):
self.n = n
def is_prime(n):
if n <2:
return False
if n == 2:
return True
for i in range(2,int(math.sqrt(n))):
if n%i == 0:
return False
return True
c = []
for i in range(1,n,2):
if is_prime(i):
c.append(i)
return len(c)
```

Alternatively, I am using the following implementation:

```
def countPrimes( n):
numbers = set(range(n,1,-1))
primes = []
while numbers:
p = numbers.pop()
primes.append(p)
numbers.difference_update(set(range(2*p,n+1,p)))
return primes
```

In the first case, the error is : Time exceeds

In the 2nd case, the error is : Memory exceeds

But both runs fine on my laptop.

Any explanation would be appreciated.

Thanks