| ▲ | Nevermark 14 hours ago | |||||||
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 :) | ||||||||
| ||||||||
| ▲ | 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). | ||||||||
| ||||||||