%I #17 Feb 11 2021 02:45:17
%S 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,
%T 89,1,90,91,181,1,182,183,365,548,913,1461,2374,3835,6209,10044,16253,
%U 1,16254,16255,32509,48764
%N a(n) = 1 if a(n-1) is prime, otherwise a(n-1) + a(n-2), with a(0) = 0 and a(1) = 1.
%H Harvey P. Dale, <a href="/A142878/b142878.txt">Table of n, a(n) for n = 0..1000</a>
%F a(n) = 1 if a(n-1) is prime, otherwise a(n-1) + a(n-2), with a(0) = 0 and a(1) = 1.
%t (* First program *)
%t a[n_]:= a[n]= If[n<2, n, If[PrimeQ[a[n-1]], 1, a[n-1] + a[n-2]]];
%t Table[a[n], {n, 0, 50}]
%t (* Second program *)
%t nxt[{a_,b_}]:={b,If[PrimeQ[b],1,a+b]}; NestList[nxt,{0,1},50][[All,1]] (* _Harvey P. Dale_, Jan 31 2020 *)
%o (Sage)
%o @CachedFunction
%o def a(n):
%o if (n<2): return n
%o elif (is_prime(a(n-1))): return 1
%o else: return a(n-1) + a(n-2)
%o [a(n) for n in (0..50)] # _G. C. Greubel_, Feb 10 2021
%K nonn,easy
%O 0,4
%A _Roger L. Bagula_, Sep 28 2008
%E Edited by _G. C. Greubel_, Feb 10 2021
|