Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Performance of Prime Generator (Burton Samograd)


----------------------------------------------------------------------

Message: 1
Date: Mon, 23 Jan 2012 08:30:45 -0700
From: Burton Samograd <[email protected]>
Subject: Re: [Haskell-beginners] Performance of Prime Generator
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain

Zhi-Qiang Lei <[email protected]> writes:
> I have bungled the Prime Generator on SPOJ for many times. Although
> the program is faster and faster on my machine, but it keeps "time
> limited exceeded" on SPOJ (6 seconds limit). Now my approach is for
> every number in the range, check if it is prime by checking if can be
> divided by all the primes smaller than or equal its square root. For
> the numbers between 999900000 and 1000000000, it take 0.64 seconds on
> my laptop. Could anyone give me some hints to enhance it? Thanks.

There are some pretty good examples of fast prime generators here:

http://www.haskell.org/haskellwiki/Prime_numbers

although using them for SPOJ is a bit like cheating :)  I learned a lot
from that page though, so I advise giving it a good readover.

--
Burton Samograd
http://kruhft.dyndns.org




------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 43, Issue 28
*****************************************

Reply via email to