A338938 a(1)=0. For n >= 2, let S be the sum of all nonprime digits in a(1), a(2), ... a(n-1) and let P be the next prime not already in the sequence. If S is a nonprime number less than P and not already in the sequence, a(n) = S. Otherwise, a(n) = P.
0, 2, 3, 5, 7, 11, 13, 17, 4, 8, 16, 19, 23, 29, 31, 37, 41, 43, 47, 53, 56, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257
Offset: 1
Examples
a(9) = 4 since the sum of the nonprime digits of the previous terms is 1+1+1+1 = 4 and 4 is less than the next prime, 19. a(10) = 8 since the sum of nonprime digits of the previous terms is 1+1+1+1+4 = 8 and 8 is less than the next prime, 19. a(11) = 16 since the sum of the nonprime digits of the previous terms is 1+1+1+1+4+8 = 16 and 16 is less than the next prime, 19. Now, the sum of the nonprime digits of the previous terms is 1+1+1+1+4+8+1+6 = 23 (a prime number). So a(12) is the next prime number in that hasn't appeared, meaning a(12) = 19.
Crossrefs
Cf. A338925.
Programs
-
PARI
my(v=[0], w=[0], n=1, p=1, m, c); while(n<125, q=vecsum(w);m=[];p=nextprime(p);c=0; for(k=1,#digits(q),if(!isprime(digits(q)[k]),m=concat(m,digits(q)[k])));if(!isprime(q)&&(q
Comments