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

%I #25 Mar 10 2023 02:26:32

%S 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,

%T 26,26,28,30,31,29,33,27,20,35,34,33,39,41,40,16,43,38,40,47,25,49,49,

%U 44,46,49,51,55,39,57,57,59,58,59,62,57,61,58,66,61,67

%N 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.

%H Neal Gersh Tolunsky, <a href="/A361178/b361178.txt">Table of n, a(n) for n = 1..10000</a>

%e 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.

%t 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 *)

%o (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

%Y Cf. A000040, A361231, A361199.

%K sign

%O 1,2

%A _Tamas Sandor Nagy_, Mar 03 2023

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 09:01 EDT 2024. Contains 374547 sequences. (Running on oeis4.)