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”).

A142878
a(n) = 1 if a(n-1) is prime, otherwise a(n-1) + a(n-2), with a(0) = 0 and a(1) = 1.
1
0, 1, 1, 2, 1, 3, 1, 4, 5, 1, 6, 7, 1, 8, 9, 17, 1, 18, 19, 1, 20, 21, 41, 1, 42, 43, 1, 44, 45, 89, 1, 90, 91, 181, 1, 182, 183, 365, 548, 913, 1461, 2374, 3835, 6209, 10044, 16253, 1, 16254, 16255, 32509, 48764
OFFSET
0,4
LINKS
FORMULA
a(n) = 1 if a(n-1) is prime, otherwise a(n-1) + a(n-2), with a(0) = 0 and a(1) = 1.
MATHEMATICA
(* First program *)
a[n_]:= a[n]= If[n<2, n, If[PrimeQ[a[n-1]], 1, a[n-1] + a[n-2]]];
Table[a[n], {n, 0, 50}]
(* Second program *)
nxt[{a_, b_}]:={b, If[PrimeQ[b], 1, a+b]}; NestList[nxt, {0, 1}, 50][[All, 1]] (* Harvey P. Dale, Jan 31 2020 *)
PROG
(Sage)
@CachedFunction
def a(n):
if (n<2): return n
elif (is_prime(a(n-1))): return 1
else: return a(n-1) + a(n-2)
[a(n) for n in (0..50)] # G. C. Greubel, Feb 10 2021
CROSSREFS
Sequence in context: A325365 A177687 A219356 * A299774 A362254 A341866
KEYWORD
nonn,easy
AUTHOR
Roger L. Bagula, Sep 28 2008
EXTENSIONS
Edited by G. C. Greubel, Feb 10 2021
STATUS
approved