OFFSET
0
COMMENTS
REFERENCES
Donald E. Knuth, The Art of Computer Programming, Vol. 2, Seminumerical Algorithms, problem 39, page 76.
EXAMPLE
For example, the binary numbers 1, 11, and 111 expressed in base 10 are 1, 3, and 7, which are prime with the exception of the first term. The next term in the binary number must be 0 because the binary number 1111 is composite.
MATHEMATICA
seq[len_] := Module[{s = {1}, k = 1, m = 1, d}, While[k < len, m *= 2; d = Boole@PrimeQ[m + 1]; m += d; AppendTo[s, d]; k++]; s]; seq[100] (* Amiram Eldar, Oct 19 2021 *)
PROG
(HTML/JavaScript)
<html>
<script>
binary="1";
for(k=0; k<30; k++)
{
if(isprime(parseInt(binary+"1", 2))==true)
{
binary=binary+"1";
}
if(isprime(parseInt(binary+"1", 2))==false)
{
binary=binary+"0";
}
}
document.write(binary);
function isprime(x)
{
for(i=2; i<(x-1); i++)
{
if(x%i==0)
{
return false;
}
}
return true;
}
</script>
</html>
CROSSREFS
KEYWORD
AUTHOR
Michael R. Page, Oct 19 2021
STATUS
approved