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.

User: Katarzyna Matylla

Katarzyna Matylla's wiki page.

Katarzyna Matylla has authored 7 sequences.

A296103 Number of shapes of left-leaning height-balanced AVL trees with n (inner) nodes.

Original entry on oeis.org

1, 1, 1, 1, 1, 2, 2, 2, 3, 5, 7, 9, 11, 13, 17, 26, 42, 66, 97, 134, 180, 241, 321, 424, 564, 774, 1111, 1661, 2545, 3925, 6012, 9079, 13480, 19678, 28296, 40212, 56701, 79599, 111469, 155795, 217301, 302590, 421396, 588782, 828633, 1178919, 1699502, 2483695
Offset: 0

Author

Katarzyna Matylla, Dec 04 2017

Keywords

Comments

A left-leaning AVL tree is a binary rooted tree where at any node, the height of left subtree is equal to the height of right subtree or greater by 1.

Crossrefs

Cf. A006265.

Programs

  • Maple
    B:= proc(x, y, d, a, b) option remember; `if`(a+b<=d,
          B(x^2+x*y, x, d, a+b, a)+x, x)
        end:
    a:= n-> coeff(B(z, 0, n+1, 1, 1), z, n+1):
    seq(a(n), n=0..60);  # Alois P. Heinz, Dec 05 2017
  • Mathematica
    B[x_, y_, d_, a_, b_] := B[x, y, d, a, b] = If[a + b <= d, B[x^2 + x*y, x, d, a + b, a] + x, x];
    a[n_] :=  Coefficient[B[z, 0, n+1, 1, 1], z, n+1];
    Table[a[n], {n, 0, 60}] (* Jean-François Alcover, May 31 2019, after Alois P. Heinz *)
  • Python
    # see link above

A296062 Base-2 logarithm of the number of different shapes of balanced binary trees with n nodes (A110316).

Original entry on oeis.org

0, 0, 1, 0, 2, 2, 2, 0, 3, 4, 5, 4, 5, 4, 3, 0, 4, 6, 8, 8, 10, 10, 10, 8, 10, 10, 10, 8, 8, 6, 4, 0, 5, 8, 11, 12, 15, 16, 17, 16, 19, 20, 21, 20, 21, 20, 19, 16, 19, 20, 21, 20, 21, 20, 19, 16, 17, 16, 15, 12, 11, 8, 5, 0, 6, 10, 14, 16, 20, 22, 24, 24, 28
Offset: 0

Author

Katarzyna Matylla, Dec 04 2017

Keywords

Comments

Since terms of A110316 are always powers of 2, it seems natural to have a sequence of the exponents too. Also, it conveys the same information as A110316 but is shorter and more readable.
Also, sum of absolute distances from (n+1) to the nearest multiple of 2^k for all 2^k < n+1. - Ivan Neretin, Jul 03 2018
Also, the minimum cost of connecting n+1 nodes when the cost of joining two connected components is the absolute difference of their sizes. In particular, connecting two equal sized components has zero cost. For example, in the case of n=4 there are 5 nodes. Connecting nodes 1 and 2 costs zero, connecting nodes 3 and 4 costs zero, then connecting {5} to {3,4} costs 1 and finally connecting {1,2} to {3,4,5} costs 1 giving a total cost of 2. Because this solution is optimal a(4) = 2. - Qingnian Su, Nov 03 2018
Also, the minimum Colless index of a rooted bifurcating tree with n leaves. - Francesc Rosselló, Apr 08 2019
Also, dilations of the Takagi function restricted to dyadic rationals in [0,1]. The number of points of a(n) in each dilation is 2^k and the scale of each dilation in both the x and y directions is 2^k, where k = floor(log_2(n+1)). See Allaart et. al (2012), Equation 4.7, attributed to Kruppel (2007). Also see Coronado et.al (2020), Corollary 4. - Laura Monroe, Oct 23 2020

References

  • Hsien-Kuei Hwang, S, Janson, T.-H. Tsai, Identities and periodic oscillations of divide-and-conquer recurrences splitting at half, arXiv:2210.10968, 2022.

Crossrefs

Programs

  • Maple
    a:= proc(n) option remember; local r; `if`(n<2, 0,
          `if`(irem(n, 2, 'r')=0, 1+a(r)+a(r-1), a(r)*2))
        end:
    seq(a(n), n=0..100);  # Alois P. Heinz, Dec 04 2017
  • Mathematica
    Fold[Append[#1, If[EvenQ@ #2, #1[[#2/2 + 1]] + #1[[#2/2]] + 1, 2 #1[[(#2 - 1)/2 + 1]]]] &, {0, 0}, Range[2, 72]] (* Michael De Vlieger, Dec 04 2017 *)
  • PARI
    seq(n)={my(v=vector(n)); for(m=2, #v, v[m]=vecmin(vector(m\2, i, v[i] + v[m-i] + m-2*i))); v} \\ Andrew Howroyd, Nov 04 2018
    
  • PARI
    seq(n)={my(v=vector(n)); for(n=1, n-1, v[n+1]=if(n%2, 2*v[(n+1)/2], v[n/2] + v[n/2+1] + 1)); v} \\ Andrew Howroyd, Nov 04 2018
    
  • Python
    def A296062(n): return (k:=n+1)-(sum(i.bit_count() for i in range(1,k))<<1)+k*(m:=k.bit_length())-(1<Chai Wah Wu, Mar 02 2023

Formula

a(0) = a(1) = 0; a(2*n) = a(n) + a(n-1) + 1; a(2*n+1) = 2*a(n).
a(n) = A007814(A110316(n)).
2^a(n) = A110316(n).
G.f. g(x) satisfies g(x) = (1+x)^2*g(x^2) + x^2/(1-x^2). - Robert Israel, Dec 04 2017
a(n) = min_{i=1..floor((n+1)/2)} n + 1 - 2*i + a(i-1) + a(n-i). - Qingnian Su and Andrew Howroyd, Nov 04 2018
a(n) = Sum_{j=2..k} (m_1-m_j-2*(j-2))*2^m_j where m_1 > ... > m_k are the exponents in the binary expansion of n. - Francesc Rosselló, Apr 08 2019
From Laura Monroe, Oct 23 2020: (Start)
a(n+1) = (2^k)*tau(x/(2^k)), where tau is the Takagi function, and n = (2^k) + x with x < 2^k.
a(n) = n - A268289(n). (End)

A236854 Self-inverse permutation of natural numbers: a(1)=1, then a(p_n)=c_{a(n)}, a(c_n)=p_{a(n)}, where p_n = n-th prime, c_n = n-th composite.

Original entry on oeis.org

1, 4, 9, 2, 16, 7, 6, 23, 3, 53, 26, 17, 14, 13, 83, 5, 12, 241, 35, 101, 59, 43, 8, 41, 431, 11, 37, 1523, 75, 149, 39, 547, 277, 191, 19, 179, 27, 3001, 31, 157, 24, 12763, 22, 379, 859, 167, 114, 3943, 1787, 1153, 67, 1063, 10, 103, 27457, 127, 919, 89, 21
Offset: 1

Author

Antti Karttunen, Feb 01 2014, based on Katarzyna Matylla's original but misplaced definition for A135044 from Feb 11 2008

Keywords

Comments

Shares with A026239 the property that the prime-positions 2, 3, 5, 7, ... contain only composite values and the composite-positions 4, 6, 8, 9, ..., etc. contain only prime values. However, instead of placing terms in those subsets in monotone order this sequence recursively permutes the order of both subsets with the emerging permutation itself, so this is a kind of "deep" variant of A026239. Alternatively, this can be viewed as yet another "entanglement permutation", where two pairs of complementary subsets of natural numbers are entangled with each other. In this case a complementary pair primes/composites (A000040/A002808) is entangled with a complementary pair composites/primes.
Maps A006508 to A007097 and vice versa.

Examples

			a(5)=c(a(3))=c(9)=16, because 5=prime(3), and the 9th composite number is c(9)=16.
Thus a(10)=prime(a(5))=prime(16)=53 (since 10 is the 5th composite), a(18)=prime(a(10))=prime(53)=241 (since 18 is the 10th composite), a(28)=prime(a(18))=prime(241)=1523.
A significant record value is a(198) = prime(a(152)) = prime(563167303) since 198=c(152); a(152)=prime(a(115)) since 152=c(115); a(115)=prime(a(84)); a(84)=prime(a(60)); a(60)=prime(a(42)); a(42)=prime(a(28)).
		

Crossrefs

Differs from A135044 for the first time at n=8, where A135044(8)=13, while here a(8)=23.

Programs

  • Mathematica
    terms = 150; cc = Select[Range[4, 2 terms^2(*empirical*)], CompositeQ]; compositePi[k_?CompositeQ] := FirstPosition[cc, k][[1]]; a[1] = 1; a[p_?PrimeQ] := a[p] = cc[[a[PrimePi[p]]]]; a[k_] := a[k] = Prime[a[ compositePi[k]]]; Array[a, terms] (* Jean-François Alcover, Mar 02 2016 *)
  • PARI
    A236854(n)={if(isprime(n), A002808(A236854(primepi(n))), n==1&&return(1);prime(A236854(n-primepi(n)-1)))} \\ without memoization: not much slower. - M. F. Hasler, Feb 03 2014
    
  • PARI
    a236854=vector(999);a236854[1]=1;A236854(n)={a236854[n]&&return(a236854[n]); a236854[n]=if(isprime(n), A002808(A236854(primepi(n))), prime(A236854(n-primepi(n)-1)))} \\ Version with memoization. - M. F. Hasler, Feb 03 2014
    
  • Python
    from sympy import primepi, prime, isprime
    def a002808(n):
        m, k = n, primepi(n) + 1 + n
        while m != k: m, k = k, primepi(k) + 1 + n
        return m # this function from Chai Wah Wu
    def a(n): return n if n<2 else a002808(a(primepi(n))) if isprime(n) else prime(a(n - primepi(n) - 1))
    print([a(n) for n in range(1, 101)]) # Indranil Ghosh, Jun 07 2017

Formula

a(1)=1, a(p_i) = A002808(a(i)) for primes with index i, a(c_j) = A000040(a(j)) for composites with index j (where 4 has index 1, 6 has index 2, and so on).

Extensions

Values double-checked by M. F. Hasler, Feb 03 2014

A135044 a(1)=1, then a(c) = p and a(p) = c, where c = T_c(r,k) and p = T_p(r,k), and where T_p contains the primes arranged in rows by the prime index chain and T_c contains the composites arranged in rows by the order of compositeness. See Formula.

Original entry on oeis.org

1, 4, 9, 2, 16, 7, 6, 13, 3, 19, 26, 17, 8, 23, 41, 5, 12, 67, 10, 29, 59, 37, 14, 83, 179, 11, 43, 331, 20, 47, 39, 109, 277, 157, 53, 431, 22, 1063, 31, 191, 15, 2221, 27, 61, 211, 71, 30, 599, 1787, 919, 241, 3001, 35, 73, 8527, 127, 1153, 79, 21, 19577, 44, 89, 283
Offset: 1

Author

Katarzyna Matylla, Feb 11 2008

Keywords

Comments

Exchanges primes with composites, primeth primes with composith composites, etc.
Exchange the k-th prime of order j with the k-th composite of order j and vice versa.
Self-inverse permutation of positive integers.
If n is the composite number A236536(r,k), then a(n) is the corresponding prime A236542(r,k) at the same position (r,k). Vice versa, if n is the prime A236542(r,k), then a(n) is the corresponding composite A236536(r,k) at the same position. - Andrew Weimholt, Jan 28 2014
The original name for this entry did not produce this sequence, but instead A236854, which differs from this permutation for the first time at n=8, where A236854(8)=23, while here a(8)=13. - Antti Karttunen, Feb 01 2014

Examples

			From _Andrew Weimholt_, Jan 29 2014: (Start)
More generally, takes the primes organized in an array according to the sieving process described in the Fernandez paper:
        Row[1](n) = 2, 7, 13, 19, 23, ...
        Row[2](n) = 3, 17, 41, 67, 83, ...
        Row[3](n) = 5, 59, 179, ...
        Row[4](n) = 11, 277, ...
        Lets call this  T_p (n, k)
Also take the composites organized in a similar manner, except we use "composite" numbered positions in our sieve:
        Row[1](n) = 4, 6, 8, 10, 14, 20, 22, ...
        Row[2](n) = 9, 12, 15, 18, 24, ...
        Row[3](n) = 16, 21, 25, ...
        Lets call this T_c (n, k)
If we now take the natural numbers and swap each number (except for 1) with the number which holds the same spot in the other array, then we get the sequence: 1, 4, 9, 2, 16, 7, 6, 13, with for example a(8) = 13 (13 holds the same position in the 'prime' table as 8 does in the 'composite' table). (End)
		

Programs

  • Maple
    A135044 := proc(n)
        if n = 1 then
            1;
        elif isprime(n) then
            idx := -1 ;
            for r from 1 do
                for c from 1 do
                    if A236542(r,c) = n then
                        idx := [r,c] ;
                    end if;
                    if A236542(r,c) >= n then
                        break;
                    end if;
                end do:
                if type(idx,list)  then
                    break;
                end if;
            end do:
            A236536(r,c) ;
        else
            idx := -1 ;
            for r from 1 do
                for c from 1 do
                    if A236536(r,c) = n then
                        idx := [r,c] ;
                    end if;
                    if A236536(r,c) >= n then
                        break;
                    end if;
                end do:
                if type(idx,list)  then
                    break;
                end if;
            end do:
            A236542(r,c) ;
        end if;
    end proc: # R. J. Mathar, Jan 28 2014
  • Mathematica
    Composite[n_Integer] := Block[{k = n + PrimePi@n + 1}, While[k != n + PrimePi@k + 1, k++ ]; k]; Compositeness[n_] := Block[{c = 1, k = n}, While[ !(PrimeQ@k || k == 1), k = k - 1 - PrimePi@k; c++ ]; c]; Primeness[n_] := Block[{c = 1, k = n}, While[ PrimeQ@k, k = PrimePi@k; c++ ]; c];
    ckj[k_, j_] := Select[ Table[Composite@n, {n, 10000}], Compositeness@# == j &][[k]]; pkj[k_, j_] := Select[ Table[Prime@n, {n, 3000}], Primeness@# == j &][[k]]; f[0]=0; f[1] = 1;
    f[n_] := If[ PrimeQ@ n, pn = Primeness@n; ckj[ Position[ Select[ Table[ Prime@ i, {i, 150}], Primeness@ # == pn &], n][[1, 1]], pn], cn = Compositeness@n; pkj[ Position[ Select[ Table[ Composite@ i, {i, 500}], Compositeness@ # == cn &], n][[1, 1]], cn]]; Array[f, 64] (* Robert G. Wilson v *)

Formula

a(1)=1, a(A236536(r,k))=A236542(r,k), a(A236542(r,k))=A236536(r,k)

Extensions

Edited, corrected and extended by Robert G. Wilson v, Feb 18 2008
Name corrected by Andrew Weimholt, Jan 29 2014

A135591 a(1)=1; for n > 1, a(n) is number of earlier terms equal to number of proper divisors of n.

Original entry on oeis.org

1, 1, 2, 1, 3, 1, 4, 1, 1, 1, 7, 0, 7, 1, 1, 1, 10, 0, 10, 0, 1, 1, 12, 2, 2, 1, 1, 0, 14, 2, 14, 0, 1, 1, 1, 0, 17, 1, 1, 2, 19, 2, 19, 0, 0, 1, 20, 0, 6, 0, 1, 0, 21, 2, 1, 2, 1, 1, 24, 0, 24, 1, 0, 1, 1, 2, 27, 0, 1, 2, 28, 0, 28, 1, 0, 0, 1, 2, 30, 0, 1, 1, 32, 0, 1, 1, 1, 2, 35, 0, 1, 0, 1, 1, 1, 0, 39
Offset: 1

Author

Katarzyna Matylla, Feb 25 2008

Keywords

Comments

Similar to A125087, but instead of exponents, we use number of proper divisors.

Examples

			a(12)=0 because 12 has 5 proper divisors (1, 2, 3, 4 and 6) and there is no 5 in a(1), a(2), ..., a(11).
		

Crossrefs

Programs

  • Mathematica
    s={1};Do[AppendTo[s,Count[s,DivisorSigma[0,n]-1]],{n,2,97}];s (* James C. McMahon, Apr 16 2025 *)
  • Maxima
    max:1000; f:makelist(0,i,1,max); apr:makelist(0, i, 0, max); f[1]:1; apr[2]:1; for n:2 through max do block(f[n]:apr[divsum(n,0)], apr[f[n]+1]:apr[f[n]+1]+1);

A135592 a(1)=1; for n > 1, a(n) is number of earlier terms equal to number of prime divisors of n.

Original entry on oeis.org

1, 1, 2, 2, 2, 3, 2, 2, 2, 6, 2, 7, 2, 8, 8, 2, 2, 10, 2, 11, 11, 11, 2, 12, 2, 13, 2, 14, 2, 1, 3, 3, 15, 15, 15, 15, 3, 15, 15, 15, 3, 5, 3, 15, 15, 15, 3, 15, 3, 15, 15, 15, 3, 15, 15, 15, 15, 15, 3, 10, 3, 15, 15, 3, 15, 12, 3, 15, 15, 13, 3, 15, 3, 15, 15, 15, 15, 15, 3, 15, 3, 15, 3, 18
Offset: 1

Author

Katarzyna Matylla, Feb 25 2008

Keywords

Comments

Similar to A125087, but instead of exponents, we use number of prime divisors.

Examples

			a(12)=7 because 12 has 2 prime divisors (2 and 3) and there are 7 2's in a(1), a(2), ..., a(11).
		

Crossrefs

Programs

  • Mathematica
    s={1};Do[AppendTo[s,Count[s,PrimeNu[n]]],{n,2,84}];s (* James C. McMahon, Apr 16 2025 *)
  • Maxima
    max:1000; f:makelist(0,i,1,max); apr:makelist(0, i, 1, max); f[1]:1; apr[2]:1; print(1,1); for n:2 through max do block(f[n]:apr[length(ifactors(n))+1], apr[f[n]+1]:apr[f[n]+1]+1);

A135141 a(1)=1, a(p_n)=2*a(n), a(c_n)=2*a(n)+1, where p_n = n-th prime, c_n = n-th composite number.

Original entry on oeis.org

1, 2, 4, 3, 8, 5, 6, 9, 7, 17, 16, 11, 10, 13, 19, 15, 12, 35, 18, 33, 23, 21, 14, 27, 39, 31, 25, 71, 34, 37, 32, 67, 47, 43, 29, 55, 22, 79, 63, 51, 20, 143, 26, 69, 75, 65, 38, 135, 95, 87, 59, 111, 30, 45, 159, 127, 103, 41, 24, 287, 70, 53, 139, 151, 131, 77, 36, 271, 191
Offset: 1

Author

Katarzyna Matylla, Feb 13 2008

Keywords

Comments

A permutation of the positive integers, related to A078442.
a(p) is even when p is prime and is divisible by 2^(prime order of p).
From Robert G. Wilson v, Feb 16 2008: (Start)
What is the length of the cycle containing 10? Is it infinite? The cycle begins 10, 17, 12, 11, 16, 15, 19, 18, 35, 29, 34, 43, 26, 31, 32, 67, 36, 55, 159, 1055, 441, 563, 100, 447, 7935, 274726911, 1013992070762272391167, ... Implementation in Mmca: NestList[a(AT)# &, 10, 26] Furthermore, it appears that any non-single-digit number has an infinite cycle.
Records: 1, 2, 4, 8, 9, 17, 19, 35, 39, 71, 79, 143, 159, 287, 319, 575, 639, 1151, 1279, 2303, 2559, 4607, 5119, 9215, 10239, 18431, 20479, 36863, 40959, 73727, 81919, 147455, 163839, 294911, 327679, 589823, 655359, ..., . (End)

Examples

			a(20) = 33 = 2*16 + 1 because 20 is 11th composite and a(11)=16. Or, a(20)=33=100001(bin). In other words it is a composite number, its index is a prime number, whose index is a prime....
		

Crossrefs

Cf. A246346, A246347 (record positions and values).
Cf. A227413 (inverse).
Cf. A071574, A245701, A245702, A245703, A245704, A246377, A236854, A237427 for related and similar permutations.

Programs

  • Haskell
    import Data.List (genericIndex)
    a135141 n = genericIndex a135141_list (n-1)
    a135141_list = 1 : map f [2..] where
       f x | iprime == 0 = 2 * (a135141 $ a066246 x) + 1
           | otherwise   = 2 * (a135141 iprime)
           where iprime = a049084 x
    -- Reinhard Zumkeller, Jan 29 2014
    
  • Mathematica
    a[1] = 1; a[n_] := If[PrimeQ@n, 2*a[PrimePi[n]], 2*a[n - 1 - PrimePi@n] + 1]; Array[a, 69] (* Robert G. Wilson v, Feb 16 2008 *)
  • Maxima
    /* Let pc = prime count (which prime it is), cc = composite count: */
    pc[1]:0;
    cc[1]:0;
    pc[2]:1;
    cc[4]:1;
    pc[n]:=if primep(n) then 1+pc[prev_prime(n)] else 0;
    cc[n]:=if primep(n) then 0 else if primep(n-1) then 1+cc[n-2] else 1+cc[n-1];
    a[1]:1;
    a[n]:=if primep(n) then 2*a[pc[n]] else 1+2*a[cc[n]];
    
  • PARI
    A135141(n) = if(1==n, 1, if(isprime(n), 2*A135141(primepi(n)), 1+(2*A135141(n-primepi(n)-1)))); \\ Antti Karttunen, Dec 09 2019
  • Python
    from sympy import isprime, primepi
    def a(n): return 1 if n==1 else 2*a(primepi(n)) if isprime(n) else 2*a(n - 1 - primepi(n)) + 1 # Indranil Ghosh, Jun 11 2017, after Mathematica code
    

Formula

a(n) = 2*A135141((A049084(n))*chip + A066246(n)*(1-chip)) + 1 - chip, where chip = A010051(n). - Reinhard Zumkeller, Jan 29 2014
From Antti Karttunen, Dec 09 2019: (Start)
A007814(a(n)) = A078442(n).
A070939(a(n)) = A246348(n).
A080791(a(n)) = A246370(n).
A054429(a(n)) = A246377(n).
A245702(a(n)) = A245703(n).
a(A245704(n)) = A245701(n). (End)