login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
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 (list; graph; refs; listen; history; text; internal format)
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
Sequence in context: A362830 A248519 A326670 * A307993 A114092 A082500
KEYWORD
sign
AUTHOR
Tamas Sandor Nagy, Mar 03 2023
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified July 23 06:59 EDT 2024. Contains 374544 sequences. (Running on oeis4.)