Talk:De Polignac numbers

From Rosetta Code
Revision as of 22:05, 27 September 2022 by Thundergnat (talk | contribs) (commentary)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Efficient algorithm

There is a quite efficient algorithm to find de Polignac numbers that several entry authors seem to have overlooked.

It is not necessary to test add every power of 2 less than N with every prime less than N and check if the sum is N.

Simply find the powers of 2 less than N, subtract N from each, and check if the remainder is a prime. If any is, it is not a de Polignac number. Short circuit and move on. --Thundergnat (talk) 22:04, 27 September 2022 (UTC)