OFFSET
1,1
LINKS
R. J. Mathar and Robert Israel, Table of n, a(n) for n = 1..7948 (1..493 from Mathar)
FORMULA
A000040 INTERSECTION {sequence starting with 1 and such that if n appears so do 2n, 3n+2, 6n+3}.
MAPLE
N:= 3000: # to get all terms <= N
A:= Vector(N):
A[1]:= 1:
todo:= {1}:
while todo <> {} do
x:= todo[1];
todo:= todo[2..-1];
Y:= select(t -> (t <= N and A[t] = 0), [2*x, 3*x+2, 6*x+3]);
A[Y]:= 1;
todo:= todo union convert(Y, set);
od:
select(t -> A[t]=1 and isprime(t), [$1..N]); # Robert Israel, Jun 17 2015
PROG
(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 */
(MATLAB)
N = 10^4;
A = zeros(1, N);
todo = [1];
A(1) = 1;
while numel(todo) > 0
x = todo(1);
todo = todo(2:end);
Y = [2*x, 3*x+2, 6*x+3];
Y = Y(Y <= N);
Y = Y(A(Y) == 0);
A(Y) = 1;
todo = [todo, Y];
end;
S = find(A==1);
S(isprime(S)) % Robert Israel, Jun 17 2015
(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)
print1(2); forprime(p=5, 1e5, if(p%3==2 && has(p\3), print1(", "p))) \\ Charles R Greathouse IV, Sep 15 2015
CROSSREFS
KEYWORD
easy,nonn
AUTHOR
Jonathan Vos Post, Aug 18 2006
EXTENSIONS
More terms from R. J. Mathar, Aug 20 2006
STATUS
approved