Max
Max

Reputation: 537

MemoryError in python- Is there any possible modification to fix it?

I am trying to run the following code in sublime text:

def max_prime_factor(num):
    divisibles=[]
    prime_facors=[]
    for i in range(1,num):
        if num%i==0:
            divisibles.append(i)
        else:
            continue
    for j in divisibles:
        for k in range(2,j):
            if j%k==0:
                break
            else:
                continue

        prime_facors.append(j)
    return(max(prime_facors))

print(max_prime_factor(600851475143))

using a machine equipped with:

enter image description here

and getting the following error in the sublime text. Do I have to modify the code, because it is overwhelming? Tnx in advance!

enter image description here

Upvotes: 0

Views: 72

Answers (1)

hostingutilities.com
hostingutilities.com

Reputation: 9539

From the comments it sounds like you're using Python 2. In that case you will need to use xrange instead or range. xrange works the same as range, but it is more memory efficent. See What is the difference between range and xrange functions in Python 2.X?

Upvotes: 1

Related Questions