-
GoPrime solution_2 is genius, but I could use some help understanding how it works on the base algorithm. Anyone able to comment? It's about 2X faster than my own Go code, following Dave's C++ example.
How is q, the square root of the sieve, further divided by 2, able to work? Most of the other algorithms don't do this. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello. Factor and q represent indices, not numbers themselves. This allows the program not to store even numbers and not to convert a number to its index on every assignment. And inverse logic is there just because Go initialises all elements to 0, so it would be a waste of resources to re-initialize the whole array to 0xff. |
Beta Was this translation helpful? Give feedback.
Hello. Factor and q represent indices, not numbers themselves. This allows the program not to store even numbers and not to convert a number to its index on every assignment. And inverse logic is there just because Go initialises all elements to 0, so it would be a waste of resources to re-initialize the whole array to 0xff.