Re: Vernon's Prime Sieve

From: Daniel McLaury (daniel_mcl_at_hotmail.com)
Date: 07/29/04


Date: 28 Jul 2004 22:42:44 -0700

Most compilers, including gcc, are smart enough to recognize walking an
array and create the extra variable for you, so I prefer to leave the
code as it stands for readability. And as to avoiding the modulus,
well, is there a better way to find the multiple of p which is closest
to N?

The Big-O is what matters; doubling the speed of something is really
not all that important compared to designing the program logic in a
manner which makes the calculations scale better on the input size.
After reviewing my code, I think that perhaps it might be better to
calculate the first 65536 primes and then loop through the numbers from
65537 to 2^32 and check each one with each prime, aborting when the
first one is found; in order to be sure, however, I'd have to do some
pencil and paper work; it's kinda hard for me to think while I type.

Finally, keep in mind that every time you print out an n-digit number
in decimal, you do n divisions, so adding a division somewhere in a
loop isn't really gonna hurt things all that much if there's printing
being done inside the loop.

I'll change the malloc values, and if that doesn't work, I'll try some
debugging.



Relevant Pages

  • Re: First Program Bug (Newbie)
    ... I used the incrementing command and incremented candidates by two to check only odds and now the program is a lot faster. ... head to write a program to print all the primes; ... The program prints some non-prime numbers. ... outer while loop: ...
    (comp.lang.python)
  • Re: First Program Bug (Newbie)
    ... head to write a program to print all the primes; ... The program prints some non-prime numbers. ... outer while loop: ... throw this away and use gmpy. ...
    (comp.lang.python)
  • RE: Error 3021
    ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)
  • RE: Error 3021
    ... Kevin Backmann ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)
  • RE: Error 3021
    ... Create proto-file names using the selected job names and storre to an array ... Save and close the document and repeat the loop ... Dim strJobsAs String, strDocsAs String, varValsAs _ ...
    (microsoft.public.access.modulesdaovba)