login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A175856 a(n) = a(n-1) - 1 if n is composite, a(n) = n otherwise. 9
1, 2, 3, 2, 5, 4, 7, 6, 5, 4, 11, 10, 13, 12, 11, 10, 17, 16, 19, 18, 17, 16, 23, 22, 21, 20, 19, 18, 29, 28, 31, 30, 29, 28, 27, 26, 37, 36, 35, 34, 41, 40, 43, 42, 41, 40, 47, 46, 45, 44, 43, 42, 53, 52, 51, 50, 49, 48, 59, 58, 61, 60, 59, 58, 57, 56, 67, 66 (list; graph; refs; listen; history; text; internal format)
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
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
Sequence in context: A212831 A072969 A139712 * A075365 A268466 A075274
KEYWORD
nonn,easy
AUTHOR
Jaroslav Krizek, Sep 29 2010
EXTENSIONS
Corrected by Jaroslav Krizek, Oct 01 2010
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified March 29 00:26 EDT 2024. Contains 371264 sequences. (Running on oeis4.)