Debdut
Debdut

Reputation: 139

Memory error in python- how to use more memory

I run this short program in python, but it outputs memory error. I use Sublime Text. My memory usage as I saw in System moniter was just normal, I had more than 2gb memory left.

def is_Prime(p):
    d=int(math.sqrt(p))
    if (p**2)% 12 == 1:
        if p==1:
            return 0
        for i in range(7, d+1, 6):
            if p%i==0:
            return 0
        for i in range(5, d+1, 6):
            if p%i==0:
                return 0    
        return 1
    else:
        if p==2 or p==3:
            return 1
        return 0

is_Prime(2425967623052370772757)

Upvotes: 2

Views: 895

Answers (1)

otus
otus

Reputation: 5732

In this particular case, you could get rid of the range invocations that allocate a list, in favor of xrange that doesn't.

Upvotes: 3

Related Questions