Remarkable results with psyco and sieve of Eratosthenes

Pekka Karjalainen pkarjala at paju.oulu.fi
Thu Nov 30 08:50:58 EST 2006


In article <1164837289.295731.178070 at h54g2000cwb.googlegroups.com>,
Steve Bergman wrote:
>BTW, can this code be made any more efficient?

>def primes():
>    primes=[3]
>    for x in xrange(5,10000000,2):
>        maxfact = int(math.sqrt(x))
>        flag=True
>        for y in primes:
>            if y > maxfact:
>                break
[...]

You can omit the call to math.sqrt if you test this instead.

    y*y > x

in place of if y > maxfact: .

Pka




More information about the Python-list mailing list