OFFSET
1,1
COMMENTS
The b sequence, prefixed by 0, is A008348. The low points in b are 1 less than the terms of the present sequence, and are given in A309226. - N. J. A. Sloane, Aug 31 2019
EXAMPLE
b(1) = 2
b(2) = 5
b(3) = 0
b(4) = 7
b(5) = 18
b(3) < b(4) < b(5), so 4 is the first term of the sequence.
MAPLE
B := proc(n) option remember ; if n = 1 then 2; else if procname(n-1)-ithprime(n) < 0 then procname(n-1)+ithprime(n) ; else procname(n-1)-ithprime(n) ; fi; fi; end: A135025 := proc(n) option remember ; if n = 1 then 4; else for a from procname(n-1)+1 do if B(a-1) < B(a) and B(a) < B(a+1) then RETURN(a) ; fi; od: fi; end: for n from 1 do printf("%d, \n", A135025(n)) ; od: # R. J. Mathar, Feb 06 2009
MATHEMATICA
B[n_] := B[n] = If[n == 1, 2, If[B[n-1] - Prime[n] < 0, B[n-1] + Prime[n], B[n-1] - Prime[n]]];
a[n_] := a[n] = If[n == 1, 4, For[k = a[n-1]+1, True, k++, If[B[k-1] < B[k] && B[k] < B[k+1], Return[k]]]];
Table[Print[n, " ", a[n]]; a[n], {n, 1, 16}] (* Jean-François Alcover, Aug 16 2022, after R. J. Mathar *)
CROSSREFS
KEYWORD
nonn,more
AUTHOR
Lior Deutsch (liorde(AT)gmail.com), Feb 10 2008
EXTENSIONS
New term added by Lior Deutsch (liorde(AT)gmail.com), Oct 17 2008
Definition corrected and entry revised by Robert Israel, Michel Marcus, and N. J. A. Sloane, Sep 29 2014
a(17)-a(28) from Giovanni Resta, Oct 02 2019
STATUS
approved