%I #11 Jun 10 2024 07:01:32
%S 5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,73,79,83,89,97,101,
%T 103,107,109,113,131,137,151,157,163,167,173,179,191,193,197,199,223,
%U 227,229,233,239,251,257,263,269,271,277,283,307,311,313,317,331,337
%N Primes p such that p-6 or p+6 is prime.
%C Either or both of (p-6) and (p+6) is/are prime. - _Harvey P. Dale_, Jun 22 2019
%H Lei Zhou, <a href="/A136207/b136207.txt">Table of n, a(n) for n = 1..10000</a>
%H Eric Weisstein's World of Math, <a href="http://mathworld.wolfram.com/SexyPrimes.html">Sexy Primes</a>. [The definition in this webpage is unsatisfactory, because it defines a "sexy prime" as a pair of primes.- _N. J. A. Sloane_, Mar 07 2021]
%H Wikipedia, <a href="http://en.wikipedia.org/wiki/Sexy_prime">Sexy Primes</a>
%p isA136207 := proc(n)
%p if isprime(n) then
%p if isprime(n+6) or isprime(n-6) then
%p true;
%p else
%p false;
%p end if;
%p else
%p false ;
%p end if;
%p end proc:
%p A136207 := proc(n)
%p option remember;
%p local a;
%p if n = 1 then
%p 5 ;
%p else
%p a := nextprime(procname(n-1)) ;
%p while true do
%p if isA136207(a) then
%p return a;
%p else
%p a := nextprime(a) ;
%p end if;
%p end do:
%p end if;
%p end proc:
%p seq(A136207(n),n=1..80) ; # _R. J. Mathar_, Jun 10 2024
%t dd = 6; DistancePrimesQ1 = (PrimeQ[ # ] && PrimeQ[ # + dd]) &; DistancePrimesQ2 = (PrimeQ[ # ] && PrimeQ[ # - dd] && (# > dd)) &; DistancePrimesQQ = (DistancePrimesQ1[ # ] || DistancePrimesQ2[ # ]) &; DistancePrimes = Select[Range[ # ], DistancePrimesQQ] &; DistancePrimes[1000]
%t Alternative by _Lei Zhou_:
%t p = 3; Table[While[p = NextPrime[p]; ! (PrimeQ[p - 6] || PrimeQ[p + 6])]; p, {n, 1, 100}]
%t Select[Prime[Range[3,100]],AnyTrue[#+{6,-6},PrimeQ]&] (* Requires Mathematica version 10 or later *) (* _Harvey P. Dale_, Jun 22 2019 *)
%Y Cf. A023201, A046117, A140546 (complement).
%K nonn
%O 1,1
%A _Carlos Alves_, Dec 21 2007
|