How to resolve the algorithm Smallest number k such that k+2^m is composite for all m less than k step by step in the Raku programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Smallest number k such that k+2^m is composite for all m less than k step by step in the Raku programming language

Table of Contents

Problem Statement

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.

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.

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

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

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Smallest number k such that k+2^m is composite for all m less than k step by step in the Raku programming language

Source code in the raku programming language

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


  

You may also check:How to resolve the algorithm Mayan numerals step by step in the REXX programming language
You may also check:How to resolve the algorithm Date manipulation step by step in the REXX programming language
You may also check:How to resolve the algorithm Higher-order functions step by step in the Mathematica / Wolfram Language programming language
You may also check:How to resolve the algorithm Multiplication tables step by step in the F# programming language
You may also check:How to resolve the algorithm Anagrams step by step in the PureBasic programming language