OFFSET
1,2
LINKS
Neal Gersh Tolunsky, Table of n, a(n) for n = 1..10000
EXAMPLE
a(7) = 4 because the 4 terms a(6) + a(5) + a(4) + a(3) = 5 + 3 + 3 + 2 = 13 is the most which sum to a prime.
MATHEMATICA
a[1] = 1; a[2] = 2; a[n_] := a[n] = Module[{s = Sum[a[i], {i, 1, n - 1}], k = n - 1}, While[! PrimeQ[s] && k > 1, s -= a[n - k]; k--]; If[PrimeQ[s], k, -1]]; Array[a, 100] (* Amiram Eldar, Mar 03 2023 *)
PROG
(PARI) lista(nn) = my(va = vector(nn)); va[1] = 1; va[2] = 2; for (n=3, nn, my(s=0, kk = -1); for (k=1, n-1, s += va[n-k]; if (isprime(s), kk = k); ); va[n] = kk; ); va; \\ Michel Marcus, Mar 03 2023
CROSSREFS
KEYWORD
sign
AUTHOR
Tamas Sandor Nagy, Mar 03 2023
STATUS
approved