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-4 of 4 results.

A097454 a(n) = (number of nonprimes <= n) - (number of primes <= n).

Original entry on oeis.org

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

Views

Author

Cino Hilliard, Aug 23 2004

Keywords

Examples

			a(7) = -1 because there are 3 nonprimes <= 7 (1,4 and 6) and 4 primes <= 7 (2,3,5 and 7).
		

Crossrefs

Programs

  • Maple
    with(numtheory): seq(n-2*pi(n), n=1..93); # Emeric Deutsch, Apr 01 2006
  • Mathematica
    qp=0;lst={};Do[If[PrimeQ[n],AppendTo[lst,qp-=1],AppendTo[lst,qp+=1]],{n,6!}];lst (* Vladimir Joseph Stephan Orlovsky, Mar 15 2010 *)
    Accumulate[ -1 + 2 * Boole /@ Not /@ PrimeQ @ Range @ 100] (* Federico Provvedi, Oct 06 2013 *)
  • PARI
    compsmprimes(n) = { for(x=1,n, y=composites(x) - pi(x); print1(y",") ) }
    \\ The number of composite numbers less than or equal to n
    composites(n) = { my(c,x); c=0; for(x=1,n, if(!isprime(x),c++); ); return(c) }
    \\ pi(x) prime count function
    pi(n) = { my(c,x); c=0;forprime(x=1,n,c++);return(c) }

Formula

a(n) = 1 + A072731(n).
a(n) = n - 2*pi(n) = n - 2*A000720(n). - Wesley Ivan Hurt, Jun 16 2013
a(n) - a(n-1) = 1 - 2*A010051(n) for n > 1. - Wesley Ivan Hurt, Dec 18 2018
a(n) = A062298(n) - A000720(n). - Michel Marcus, Jan 31 2019

A118777 a(0) = 1; n > 0: a(n) = a(n-1) + d, d = +-1 if n is prime/nonprime.

Original entry on oeis.org

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

Views

Author

Zak Seidov, May 22 2006

Keywords

Crossrefs

One more than A097454, two more than A072731.
For no apparent reason, the terms a(3)..a(24) are equal to the terms a(0)..a(21) of A276090.

Programs

  • Mathematica
     Table[n + 1 - 2*PrimePi[n], {n, 0, 100}]
  • Scheme
    ;; With memoization-macro definec.
    (definec (A118777 n) (if (zero? n) 1 (+ (A118777 (- n 1)) (expt -1 (A010051 n)))))
    ;; Antti Karttunen, Aug 19 2016
    
  • Scheme
    (define (A118777 n) (+ 1 (- n (* 2 (A000720 n))))) ;; After formula given by the original author.
    ;; Antti Karttunen, Aug 19 2016

Formula

a(n) = n + 1 - 2*primepi(n), n = 0, 1, 2, ..., where primepi(n) = A000720(n).
From Antti Karttunen, Aug 21 2016: (Start)
a(0) = 1, for n >= 1, a(n) = a(n-1) + (-1)^A010051(n). (from the definition).
For all n >= 1, a(n) = 1+A097454(n) = 2+A072731(n).
(End)

Extensions

Offset and the name corrected by Antti Karttunen, Aug 19 2016

A383037 a(n) is the excess of composites over primes in the first n odd positive integers.

Original entry on oeis.org

0, -1, -2, -3, -2, -3, -4, -3, -4, -5, -4, -5, -4, -3, -4, -5, -4, -3, -4, -3, -4, -5, -4, -5, -4, -3, -4, -3, -2, -3, -4, -3, -2, -3, -2, -3, -4, -3, -2, -3, -2, -3, -2, -1, -2, -1, 0, 1, 0, 1, 0, -1, 0, -1, -2, -1, -2, -1, 0, 1, 2, 3, 4, 3, 4, 3, 4, 5, 4, 3, 4
Offset: 1

Views

Author

Felix Huber, Apr 19 2025

Keywords

Examples

			Of the first 5 odd positive integers (1, 3, 5, 7, 9), one (9) is a composite and three (3, 5, 7) are primes, so a(5) = 1 - 3 = -2.
		

Crossrefs

Programs

  • Maple
    A383037:=n->n-NumberTheory:-pi(2*n)*2+1;seq(A383037(n),n=1..71);
  • Mathematica
    a[n_]:=n - 2*PrimePi[2*n] + 1; Array[a,71] (* Stefano Spezia, Apr 20 2025 *)

Formula

a(n) = n - 2*pi(2*n) + 1.
a(n) = A210469(n) - pi(2*n) + 1 = A210469(n) - A000720(2*n) + 1 = for n > 1.
a(n) = A118777(2*n-1) - n + 1 for n > 1.
a(n) = A097454(2*n-1) - n + 2 for n > 1.
a(n) = A072731(2*n-1) - n + 3 for n > 1.

A361915 a(n) is the smallest prime p such that, for m >= nextprime(p), there are more composites than primes in the range [2, m], where multiples of primes prime(1) through prime(n) are excluded.

Original entry on oeis.org

13, 113, 1069, 5051, 18553, 44417, 99439, 190921, 356351, 603149, 933073, 1416223, 2044201, 2856559, 3957883, 5379287, 7093217, 9113263, 11693687, 14701529, 18345209, 22758829, 27879563, 33938257, 40808759, 48364003, 57099061, 67292237, 78919781, 92417891
Offset: 0

Views

Author

Ya-Ping Lu, Mar 29 2023

Keywords

Examples

			The number of primes, N_p, and the number of composite, N_c, in the range [2, m] are listed in the table below, where N_p = N_c occurs at m = 9, 11 and 13. For m >= nextprime(13) = 17, N_c > N_p. So, a(0) = 13 is the case for n = 0, in which none of the multiples of primes is excluded from the integer list.
   m:   2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, ...
   N_p: 1, 2, 2, 3, 3, 4, 4, 4,  4,  5,  5,  6,  6,  6,  6,  7, ...
   N_c: 0, 0, 1, 1, 2, 2, 3, 4,  5,  5,  6,  6,  7,  8,  9,  9, ...
If the multiples of prime(1) are excluded from the list, 113 is the smallest prime such that N_c > N_p for m >= nextprime(113) = 127 and, thus, a(1) = 113 (see below).
   m:   3, 5, 7, ..., 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, ...
   N_p: 1, 2, 3, ..., 23, 23, 24, 24,  25,  26,  26,  27,  28,  28,  29,  29, ...
   N_c: 0, 0, 0, ..., 23, 24, 24, 25,  25,  25,  26,  26,  26,  27,  27,  28, ...
If multiples of prime(1) and prime(2) are excluded, a(2) = 1069. If multiples of prime(1), prime(2) and prime(3) are excluded, a(3) = 5051.
		

Crossrefs

Programs

  • Python
    from sympy import isprime, prime
    R = []; L = [x for x in range(2, 100000001)]
    for n in range(30):
        np = 0; nc = 0; found = 0
        if n > 0: q = prime(n); L = [x for x in L if x%q != 0]
        for m in L:
            if isprime(m): np += 1; p = m
            else: nc += 1
            if np == nc: Lp = p; found = 1
        if found: R.append(Lp)
    print(*R, sep = ", ")
Showing 1-4 of 4 results.