Smallest number k such that k+2^m is composite for all m less than k

From Rosetta Code
Revision as of 23:50, 11 January 2022 by Thundergnat (talk | contribs) (New draft task and Raku example)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Smallest number k such that k+2^m is composite for all m less than k is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Generate the sequence of numbers a(k), where each k is the smallest positive integer such that k + 2m is composite for every positive integer m less than k.


For example

Suppose k == 7; test m == 1 through m == 6. If any are prime, the test fails.

Is 7 + 21 (9) prime? False

Is 7 + 22 (11) prime? True

So 7 is not an element of this sequence.

It is only necessary to test odd natural numbers k. An even number, plus any positive integer power of 2 is always composite.


Task

Find and display, here on this page, the first 5 elements of this sequence.


See also

OEIS:A033939 - Odd k for which k+2^m is composite for all m < k


Raku

<lang perl6>put (1..∞).hyper(:250batch).map(* × 2 + 1).grep( -> $k { !(1 ..^ $k).first: ($k + 1 +< *).is-prime } )[^5]</lang>

Output:
773 2131 2491 4471 5101