login
a(1) = 1 and thereafter a(n) = a(n-1) + j(n-1) where j(1) = 1 and then j(n) = j(n-1)-1 if a(n) is composite or j(n) = 2*j(n-1) if a(n) is prime.
1

%I #26 Apr 12 2025 09:42:40

%S 1,2,4,5,7,11,19,35,50,64,77,89,113,161,208,254,299,343,386,428,469,

%T 509,589,668,746,823,977,1285,1592,1898,2203,2813,3422,4030,4637,5851,

%U 8279,10706,13132,15557,17981,22829,27676,32522,37367,42211,47054,51896,56737,66419,76100,85780,95459

%N a(1) = 1 and thereafter a(n) = a(n-1) + j(n-1) where j(1) = 1 and then j(n) = j(n-1)-1 if a(n) is composite or j(n) = 2*j(n-1) if a(n) is prime.

%H Pontus von Brömssen, <a href="/A382671/b382671.txt">Table of n, a(n) for n = 1..10000</a> (first 73 terms from Alexander Markovsky)

%o (C#)

%o static int[] lista(int n){

%o int a0 = 1, j = 1;

%o int[] res = new int[n];

%o for (int i = 0; i < n; i++){

%o res[i] = a0;

%o if (a0>1){

%o if (IsPrime(a0)) //IsPrime(x) returns true if x is prime, false otherwise.

%o j *= 2;

%o else

%o j--;

%o }

%o a0 += j;

%o }

%o return res;

%o }

%o (PARI) lista(nn) = my(va = vector(nn), vj = vector(nn)); va[1] = 1; vj[1] = 1; for (n=2, nn, va[n] = va[n-1] + vj[n-1]; vj[n] = if (isprime(va[n]), 2*vj[n-1], vj[n-1]-1);); va; \\ _Michel Marcus_, Apr 03 2025

%o (Python)

%o from sympy import isprime

%o from itertools import islice

%o def agen(): # generator of terms

%o an, jn = 1, 1

%o while True:

%o yield an

%o an += jn

%o jn = 2*jn if isprime(an) else jn-1

%o print(list(islice(agen(), 53))) # _Michael S. Branicky_, Apr 10 2025

%K nonn

%O 1,2

%A _Alexander Markovsky_, Apr 02 2025