On 07/01/14 09:49, Jorge L. wrote:
I'm working through Project Euler problems, now I'm at problem 3. I did
an implementation of the shieve of Erastothenes to find the prime
numbers less than a given number. Then I run a divisibility test over
those prime numbers to find the largest prime factor of that given
number.

Please, always send the full error text not a summary.
The error message is full of useful information that helps us see exactly what was going on at the time.

It also helps if you tell us which version of Python and OS you are using. In this case the OS probably doesn't matter, but I assume you are on Python 2.X?

Here's the code:

import time

def main():
     n = input("Please enter the number to find its highest prime factor: ")
     start_time = time.clock()
     l = p(n)
     div(n,l)
     print "Execution time = ",time.clock() - start_time, "seconds"


# Sieve of Eratosthenes implementation

def p(n):
     is_p=[False]*2 + [True]*(n-1)

If n is large this will create a large list.
Do you have enough memory for a list with
600851475144 members? It may also have
something to do with your indexing problem.
I certainly can't create anything so big on
my PC.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to