Remix.run Logo
WCSTombs 15 hours ago

The example given in the article is 2^127 - 1, which was historically proved to be prime without computers using a clever method now known as the Lucas-Lehmer test. Your algorithm is not practical for that number.

Nevermark 14 hours ago | parent | next [-]

Ah, but I can assure you, it is just that simple.

If a number is not prime, then it is the product of at least two numbers smaller than itself.

If any of them are larger than its square root, all others must be smaller, or their product would be larger than the candidate prime.

Ergo, just check that the candidate is not evenly divisible by any number equal or lower than its square root.

This reasoning holds, independent of scale.

QED. Check mate. Shazam.

mysterydip 14 hours ago | parent | next [-]

Perfect example of how "if the code is compact, it's fast" can be deceiving :)

Nevermark 10 hours ago | parent [-]

Search is all you need!

If you have the time.

Or if we can expand quantum superposition algorithms from 2^N states, for quantum circuits with N control qubits, to 2^(T*N) superpositions over T time steps, via some kind of superposition tree recursion. The number of superpositions increasing exponentially for T steps (and then reducing for another T steps) on a single recursive physical circuit.

That is not supported by the physical laws we have, but it is an interesting idea.

xpe 12 hours ago | parent | prev [-]

The obvious and naive method described above is O(sqrt(N)). For N ~= 2 ^ 127, that is about 2 ^ 64. / The Lucas-Lehmer method described in the article is better (how much better is an exercise for the reader).

gsliepen 7 hours ago | parent [-]

You are assuming division itself is an O(1) operation. However, it also scales with the size of the number. So more correct would be to say that this naive method is O(sqrt(N) log(N) log(log(N))).

great_wubwub 15 hours ago | parent | prev [-]

/r/whoosh

eps 14 hours ago | parent [-]

Nah, the joke just was fairly flat and low-effort.