The algorithm is very nice. But I think you should think about what it means to divide one integer by another. The quotient of that operation is an integer. The remainder is an integer.
Can you express the number in terms of the quotient and remainder?
Using this expression write an algorithm that outputs the quotient and remainder using only addition, multiplication and checking equality with integers.
I think doing this would make the algorithm seem less surprising.
One of the first algorithms I implemented in Python was the prime sieve. I used it extensively when solving Project Euler problems as well. Good days :)
You can solve much more problems from Project Euler using a DFS variation of the Sieve of Euler. It is a depth first search of all the numbers less than n. It visits every number exactly once. When it visits a number, the prime factorization of the number is available (or any quantity derived from the factorization, like Euler's phi function).
The gaps between primes are easily produced using two operations on a list of numbers, mirroring and partitioning.
Each prime generates a spacing sequence to find future primes, each prime is effectively casting a new periodic wave function. 2 produces a wave that hits all even numbers. 3 produces a wave that hits every 6 numbers (2 already gets everything else.) 5 does every {20,10}, etc...
You can see the process of generating the sieve waveform, or more technically, the prime gaps, here:
Look at the 2nd answer, it explains the process. Remember, all prime numbers do, is cast a waveform onto the existing sieve waveform. Just chaotic interference. Division as an immediate reaction to primes is moreso because primes are taught pretty poorly. As mystic nuggets. Rather than chaotic interference.
You've posted about this "waveform" idea before, and to be honest it seems like you are making a big deal out of the obvious fact that each newly found prime eliminates some possible greater numbers from the search by being a factor.
With friendly intentions, I have to tell you that you risk sounding like a math crank.
The waveform idea is simply to convey the sieve to non math folk in a more intriguing way. I dont see how talking about first differences of reduced residue sets of primorials is crank. Its being studied as we speak by PHD Fred Holt from UWashington...
Wheres the issue with the method of mirroring and partitioning I discussed? Do you have something better than wont involve division?
Also, there is a lot of merit in understanding how the sieve works because gap sequences work until the next prime squared. As the primes tend toward infinity, the sieve matches all primes. Its a valid way to study primes aside from the attacks on the Zeta function
I am open to being convinced that you have new insights, but the reduced residue sets idea is not a magic bullet. If it was a magic bullet we would be having a different conversation.
Basically I am encouraging you to discuss this in a way or in a context in which people will engage more readily with your ideas, either to accept or reject them. HN is not full of number theorists.
Edit: This is a case where textual communication is really inadequate to determine the seriousness and, dare I say it, credibility of an interlocutor.
The coolest technique I know of for checking primes is a variant of the Lucas sequence method (which is what GIMPS uses to find Mersenne primes)[1]. Essentially, you generate terms in a sequence in a constant-memory fashion that doesn't require you to know the factors, using just a modulo in a generating function.
This algorithm seems similar to one I found* which is a Sieve of Eratosthenes that doesn't require deciding how big of an array to allocate at the beginning. Essentially, you reverse the order of the two main loops, modifying the main data structure accordingly.
I don't completely understand it yet, but I think the Dijkstra version might have optimized the structure which contains the multiples of known primes, where I just put it into a dictionary.
* I initially saw it in a paper about how the Sieve is generally implemented incorrectly in Haskell, but I made a small Python generator implementation.
implicitly filters out multiples of 2, 3, and 5, leaving only 8 potential primes in every 30 consecutive integers, conveniently fitting in a byte, for a total of 137MB.
(for some reason, compiling with nonzero optimization gives a gcc 4.8.5 internal compiler error on my SUSE Linux box)
The same holds for the Sieve of Eratosthenes [1]
[1] https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes