cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

Showing 1-2 of 2 results.

A284188 a(1)=2; thereafter a(n+1) = a(n)+i if a(n) is a prime and a(1),...,a(n) contains i primes, or a(n+1) = a(n)-i if a(n) is composite and a(1),...,a(n) contains i primes.

Original entry on oeis.org

2, 3, 5, 8, 5, 9, 5, 10, 5, 11, 18, 11, 19, 28, 19, 29, 40, 29, 41, 54, 41, 55, 41, 56, 41, 57, 41, 58, 41, 59, 78, 59, 79, 100, 79, 101, 124, 101, 125, 101, 126, 101, 127, 154, 127, 155, 127, 156, 127, 157, 188, 157, 189, 157, 190, 157, 191, 226, 191, 227, 264, 227, 265
Offset: 1

Views

Author

Bob Selcoe, Mar 21 2017

Keywords

Comments

Without repeated terms, the primes appear in order as A070865.
Variant of A284172; the difference is that in A284172, a(n+1) = a(n)-i if a(n) is composite and a(1),...,a(n) contains i composites (rather than i primes).
For n >= 3: When a(n) = prime p it is followed by an even number j at a(n+1); p repeats k-j times (where k is the smallest prime > j), appearing at a(n+2m) {m=1..k-j}. a(n+2m+1) = p+m until p+m = k (immediately following the final p); k now becomes "new p" immediately followed by a "new j", and the process repeats.

Examples

			a(10) = 11; there are 7 primes in the sequence up to and including a(10) so a(11) = 11+7 = 18. 18 is composite so a(12) = 18-7 = 11.  Now there are 8 primes in the sequence; and since 11 is prime, a(13) = 11+8 = 19 (the 9th prime in the sequence), so a(14) = 28.
		

Crossrefs

Programs

  • Maple
    c:= proc(n) option remember; `if`(n<1, 0,
          `if`(isprime(a(n)), 1, 0)+c(n-1))
        end:
    a:= proc(n) option remember; `if`(n=1, 2, (m->
          `if`(isprime(m), 1, -1)*c(n-1)+m)(a(n-1)))
        end:
    seq(a(n), n=1..100);  # Alois P. Heinz, Apr 15 2017
  • Mathematica
    Block[{c = 1, m = 2, n}, {2}~Join~Reap[Do[If[PrimeQ[m], Set[n, m + c]; c++, Set[n, m - c + 1]]; Sow[n]; m = n, 63]][[-1, -1]]] (* Michael De Vlieger, Oct 20 2021 *)
  • PARI
    lista(nn) = {print1(a=2, ", "); nbp = 1; for (n=2, nn, if (isprime(a), a += nbp, a -= nbp); print1(a, ", "); if (isprime(a), nbp++););} \\ Michel Marcus, Mar 24 2017

A284278 a(1)=2; for n >= 1, if n+2 is prime then a(2*n+1) = 3*n + 2 and a(2*n) = n + 2, otherwise all terms are 2.

Original entry on oeis.org

2, 3, 5, 4, 2, 5, 9, 6, 2, 7, 13, 8, 2, 9, 2, 10, 2, 11, 21, 12, 2, 13, 25, 14, 2, 15, 2, 16, 2, 17, 33, 18, 2, 19, 37, 20, 2, 21, 2, 22, 2, 23, 45, 24, 2, 25, 2, 26, 2, 27, 2, 28, 2, 29, 57, 30, 2, 31, 61, 32, 2, 33, 2, 34, 2, 35, 2, 36, 2, 37, 73, 38, 2, 39
Offset: 1

Views

Author

Vladimir Shevelev, Mar 24 2017

Keywords

Comments

The sequence is motivated by A284172, by the message from B. Jubin dated Mar 23 2017 and by the classic open problem of showing that there are infinitely many primes p for which 2*p-1 is also prime. If there were only finitely many such primes, then there would be a place where this sequence is generated by the same rule as A284172.
The sequence of the first differences begins 1, 2, -1, -2, 3, 4, -3, -4, 5, 6, -5, -6, 7, -7, 8, -8, 9, 10, -9, -10, 11, 12, -11, -12, 13, -13, 14, -14, 15, 16, -15, -16, 17, 18, ...
From the definition it easily follows that, for a positive x, the sequence contains roughly equal numbers of prime and composite terms <= x.
A conditional property: if there is a maximal prime P such that 2*P-1 is also prime, then for n > P, every pair (a(2*n), a(2*n+1)) contains one prime and one composite. Indeed, if n+2 is prime, then a(2*n) = n + 2 is prime, while a(2*n+1) = 2*n + 3 = 2*(n+2) - 1 is composite; if n+2 is composite, then a(2*n) = n + 2 is composite, while a(2*n+1) = 2 is prime. - Vladimir Shevelev, Mar 26 2017

Examples

			For n=19, a(38) = a(2*19) = 19+2 = 21, a(39) = a(2*19+1) = 2, the latter since 19+2 is not prime;
for n=21, a(42) = a(2*21) = 21+2 = 23, a(43) = a(2*21+1) = 2*21+3 = 45 since 21+2 is prime.
		

Crossrefs

Cf. A284172.

Programs

  • Mathematica
    a[1]:=2;
    a[n_?EvenQ]:=n/2+2;
    a[n_?OddQ]:=If[PrimeQ[(n+1)/2+1], n+2, 2];
    Map[a, Range[150]] (* Peter J. C. Moses, Mar 24 2017 *)
  • PARI
    a(n) = if(n<2, 2, if(n%2, if(isprime((n + 1)/2 + 1), n + 2, 2), (n/2 + 2))); \\ Indranil Ghosh, Mar 25 2017

Extensions

More terms from Peter J. C. Moses, Mar 24 2017
Showing 1-2 of 2 results.