OFFSET
1,2
COMMENTS
a(n) = n for noncomposite n, a(n) = 2 * (previous prime (n)) - n for composite n.
See A175859 - absent positive integers (pairs of consecutive numbers) in sequence: 8, 9, 14, 15, 24, 25, 32, 33, ...
a(n) = A075365(n) except at n = 1 and n = 10. - Alexandre Herrera, Nov 11 2023
LINKS
Alois P. Heinz, Table of n, a(n) for n = 1..10000
EXAMPLE
a(7) = 7 (7 is a noncomposite number), a(8) = 2*7 - 8 = 6 (8 is composite).
MAPLE
a:= proc(n) option remember;
`if`(n=1 or isprime(n), n, a(n-1)-1)
end:
seq(a(n), n=1..80); # Alois P. Heinz, Jun 22 2021
MATHEMATICA
a[1] := 1; a[n_] := a[n] = If[PrimeQ[n], n, a[n - 1] - 1] (* Ben Branman, Jan 02 2011 *)
nxt[{n_, a_}]:={n+1, If[CompositeQ[n+1], a-1, n+1]}; NestList[nxt, {1, 1}, 70][[All, 2]] (* Harvey P. Dale, Jan 01 2023 *)
PROG
(PARI) a(n)=if(n==1, 1, 2*precprime(n)-n) \\ Charles R Greathouse IV, Apr 22 2022~
CROSSREFS
KEYWORD
nonn,easy
AUTHOR
Jaroslav Krizek, Sep 29 2010
EXTENSIONS
Corrected by Jaroslav Krizek, Oct 01 2010
STATUS
approved