login

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 61st year, we have over 378,000 sequences, and we’ve reached 11,000 citations (which often say “discovered thanks to the OEIS”).

A361178
a(1) = 1, a(2) = 2; for n >= 3, a(n) is the greatest k where a(n-1) + a(n-2) + ... + a(n-k) is prime, or a(n) = -1 if no such k exists.
3
1, 2, 2, 3, 3, 5, 4, 6, 6, 8, 8, 10, 9, 13, 13, 8, 16, 13, 16, 6, 19, 17, 5, 23, 21, 21, 25, 27, 26, 26, 28, 30, 31, 29, 33, 27, 20, 35, 34, 33, 39, 41, 40, 16, 43, 38, 40, 47, 25, 49, 49, 44, 46, 49, 51, 55, 39, 57, 57, 59, 58, 59, 62, 57, 61, 58, 66, 61, 67
OFFSET
1,2
LINKS
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