%I #19 Dec 17 2017 07:37:39
%S 2,5,17,29,47,53,83,89,101,173,191,251,263,269,281,317,431,467,479,
%T 521,587,659,809,857,911,929,947,953,983,1019,1091,1163,1307,1439,
%U 1451,1493,1559,1601,1613,1667,1811,1847,1871,1901,1979,2027,2063,2099,2207,2243
%N Klarner-Rado primes. Primes in A005658.
%H R. J. Mathar and Robert Israel, <a href="/A120847/b120847.txt">Table of n, a(n) for n = 1..7948</a> (1..493 from Mathar)
%F A000040 INTERSECTION {sequence starting with 1 and such that if n appears so do 2n, 3n+2, 6n+3}.
%p N:= 3000: # to get all terms <= N
%p A:= Vector(N):
%p A[1]:= 1:
%p todo:= {1}:
%p while todo <> {} do
%p x:= todo[1];
%p todo:= todo[2..-1];
%p Y:= select(t -> (t <= N and A[t] = 0),[2*x,3*x+2, 6*x+3]);
%p A[Y]:= 1;
%p todo:= todo union convert(Y,set);
%p od:
%p select(t -> A[t]=1 and isprime(t), [$1..N]); # _Robert Israel_, Jun 17 2015
%o (C++) #include <stdio.h> #include <iostream> #include <set> using namespace std ; bool isprime(const int n) { for(int i=2; i*i <= n ; i++) if( n %i == 0) return false ; return true ; } int main(int argc, char *argv[]) { const int anmax= 40000 ; set<int> a ; a.insert(1) ; for(int i=0;i< anmax ;i++) { if( a.count(i) ) { if( 2*i<=anmax) a.insert(2*i) ; if( 3*i+2 <= anmax) a.insert(3*i+2) ; if( 6*i+3 <= anmax) a.insert(6*i+3) ; } } int n=1 ; for(int i=2; i < anmax; i++) { if( a.count(i) && isprime(i) ) { cout << n << " " << i << endl ; n++ ; } } return 0 ; } /* _R. J. Mathar_, Aug 20 2006 */
%o (MATLAB)
%o N = 10^4;
%o A = zeros(1,N);
%o todo = [1];
%o A(1) = 1;
%o while numel(todo) > 0
%o x = todo(1);
%o todo = todo(2:end);
%o Y = [2*x,3*x+2,6*x+3];
%o Y = Y(Y <= N);
%o Y = Y(A(Y) == 0);
%o A(Y) = 1;
%o todo = [todo, Y];
%o end;
%o S = find(A==1);
%o S(isprime(S)) % _Robert Israel_, Jun 17 2015
%o (PARI) has(n)=if(n<3, return(n>0)); my(k=n%6); if(k==3, return(has(n\6))); if(k==1, return(0)); if(k==5, return(has(n\3))); if(k!=2, return(has(n/2))); has(n\3) || has(n/2)
%o print1(2); forprime(p=5,1e5, if(p%3==2 && has(p\3), print1(", "p))) \\ _Charles R Greathouse IV_, Sep 15 2015
%Y Subsequence of A003627.
%Y Cf. A000040, A005658.
%K easy,nonn
%O 1,1
%A _Jonathan Vos Post_, Aug 18 2006
%E More terms from _R. J. Mathar_, Aug 20 2006