OFFSET
0,3
LINKS
John Tyler Rascoe, Illustration of first 15 terms
EXAMPLE
0 = 0
0 + 1 = 1
0 + 1 + 2 = 3 (prime)
0 + 1 + 2 + 1 = 4
0 + 1 + 2 + 1 + 2 = 6
0 + 1 + 2 + 1 + 2 + 3 = 9
0 + 1 + 2 + 1 + 2 + 3 + 4 = 13 (prime)
0 + 1 + 2 + 1 + 2 + 3 + 4 + 3 = 16
MATHEMATICA
a[0] = 0; a[1] = 1; a[n_] := a[n] = 2*a[n - 1] - a[n - 2] - If[PrimeQ[a[n - 1]], 1, -1]; Array[a, 50, 0] (* Amiram Eldar, Jul 23 2022 *)
PROG
(Python)
import sympy
A355697 = A = [0, 1]
for n in range(1, 100):
if sympy.isprime(A355697[-1]):
y = A[-1] - A[-2] - 1
else:
y = A[-1] - A[-2] + 1
A.append(A[-1] + y)
(MATLAB)
function a = A355697(max_n)
a = 0; m = 0;
for n = 1:max_n
if isprime(a(n))
m = m - 1;
else
m = m + 1;
end
a(n+1) = a(n) + m;
end
end % Thomas Scheuerle, Jul 22 2022
(PARI) lista(nn) = my(va = vector(nn)); va[1] = 0; va[2] = 1; for (n=3, nn, if (isprime(va[n-1]), va[n] = 2*va[n-1]-va[n-2]-1, va[n] = 2*va[n-1]-va[n-2]+1); ); va; \\ Michel Marcus, Aug 23 2022
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
John Tyler Rascoe, Jul 19 2022
STATUS
approved