OFFSET
0,4
LINKS
Harvey P. Dale, Table of n, a(n) for n = 0..1000
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
KEYWORD
nonn,easy
AUTHOR
Roger L. Bagula, Sep 28 2008
EXTENSIONS
Edited by G. C. Greubel, Feb 10 2021
STATUS
approved