Question: Integer sequence recurrence

Hi,

I am trying to write a code for the following simple recurrence:

a(1)=1,

a(n)+1prime—>a(n+1)=a(n)+1,

a(n)+1 composite —>a(n+1)=n+2

if a(n) even, or a(n)+ 3 if a(n) odd.

Data: 1,2,3,6,7,10,11,14,16,17.....

My first attempt is the following:

N:=10:

for k from 1 to N do

X:=1;

if isprime(X+1) then print(X+1);

elif not isprime(X+1) and mod(X,2)=0 

then print(X+2);

else print(X+3);

end if:

end do:

This does not work but I cannot see why. Would somebody mind to help me out with this?

 

Best regards

David.

 

 

 

Please Wait...