login
a(0) = 0 and thereafter a(n) = 2 if a(n-1) is an odd prime, otherwise a(n) = a(n-1) + k where k = n - P(n) and P(n) is the number of odd primes among terms a(0),...,a(n-1).
1

%I #22 Jul 09 2025 17:54:43

%S 0,1,3,2,5,2,6,11,2,8,15,23,2,11,2,12,23,2,14,27,41,2,17,2,18,35,53,2,

%T 21,41,2,23,2,24,47,2,26,51,77,104,132,161,191,2,33,65,98,132,167,2,

%U 38,75,113,2,41,2,42,83,2,44,87,131,2,47,2,48,95,143,192,242

%N a(0) = 0 and thereafter a(n) = 2 if a(n-1) is an odd prime, otherwise a(n) = a(n-1) + k where k = n - P(n) and P(n) is the number of odd primes among terms a(0),...,a(n-1).

%C The number of terms between consecutive 2's is never 4*d, since the sum of 4*d consecutive values of k is always even and consequently a(n+4*d) is even (not a prime).

%H Aaron Pieniozek, <a href="/A383594/b383594.txt">Table of n, a(n) for n = 0..199</a>

%e The sequence, and the k increments applied, begin

%e a(n) = 0, 1, 3, 2, 5, 2, 6, 11, 2, 8, 15, 23, ...

%e k = 1 2 3 4 5 6 7 8

%p seq := proc(n)

%p local a, i, k;

%p a := [0];

%p k := 1;

%p for i from 1 to n-1 do

%p if isprime(a[-1]) and a[-1] <> 2 then

%p a := [op(a), 2];

%p else

%p a := [op(a), a[-1] + k];

%p k := k + 1;

%p end if;

%p end do;

%p return a;

%p end proc:

%t sequence[n_] := Module[{a = {0}, k = 1},

%t While[Length[a] < n,

%t If[PrimeQ[Last[a]] && Last[a] != 2,

%t AppendTo[a, 2],

%t AppendTo[a, Last[a] + k];

%t k++

%t ];

%t ];

%t a

%t ]

%K nonn

%O 0,3

%A _Aaron Pieniozek_, May 01 2025