A163578 If n is prime, a(n) is next composite greater than a(n-1), else if n is composite, a(n) is next prime greater than a(n-1) else 2.
2, 4, 6, 7, 8, 11, 12, 13, 17, 19, 20, 23, 24, 29, 31, 37, 38, 41, 42, 43, 47, 53, 54, 59, 61, 67, 71, 73, 74, 79, 80, 83, 89, 97, 101, 103, 104, 107, 109, 113, 114, 127, 128, 131, 137, 139, 140, 149, 151, 157, 163, 167, 168, 173, 179, 181, 191, 193, 194, 197, 198, 199
Offset: 1
Examples
1 is not prime, a(1)=2. 2 is prime, a(2)=4. 3 is prime, a(3)=6. 4 is composite, a(4)=7.
Links
- Paolo Xausa, Table of n, a(n) for n = 1..10000
Programs
-
Mathematica
Join[{2, 4}, FoldList[If[PrimeQ[#2], #+1, NextPrime[#]] &, 6, Range[4, 100]]] (* Paolo Xausa, Sep 03 2025 *)
Extensions
More terms from Paolo Xausa, Sep 03 2025