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

A051010 Triangle T(m,n) giving of number of steps in the Euclidean algorithm for gcd(m,n) with 0<=m

Original entry on oeis.org

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

Views

Author

Keywords

Crossrefs

Cf. A049826.
Cf. A130130 (central terms).

Programs

  • Haskell
    a051010 n k = snd $ until ((== 0) . snd . fst)
                        (\((x, y), i) -> ((y, mod x y), i + 1)) ((n, k), 0)
    a051010_row n = map (a051010 n) [0..n-1]
    a051010_tabl = map a051010_row [1..]
    -- Reinhard Zumkeller, Jun 27 2013
  • Mathematica
    t[m_, n_] := For[r[-1]=m; r[0]=n; k=1, True, k++, r[k] = Mod[r[k-2], r[k-1]]; If[r[k] == 0, Return[k-1]]]; Table[ t[m, n] , {n, 1, 14}, {m, 0, n-1}] // Flatten (* Jean-François Alcover, Oct 25 2012 *)

A084242 Least k, 1 <= k <= n, such that the number of elements of the continued fraction for n/k is maximum.

Original entry on oeis.org

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

Views

Author

Benoit Cloitre, Jun 21 2003

Keywords

Comments

Also, for n > 1, the smallest number k such that the Euclidean algorithm for (n,k) requires the maximum number of steps, A034883(n). - T. D. Noe, Mar 24 2011

Crossrefs

Programs

  • PARI
    a(n)=if(n<0,0,s=1; while(abs(vecmax(vector(n,i,length(contfrac(n/i))))-length(contfrac(n/s)))>0,s++); s)

Formula

For k > 1, a(F(k)) = F(k-1) where F(k) denotes the k-th Fibonacci number.
Probably, lim_{n->oo} (1/n)*Sum_{k=1..n} a(k) = 1/phi = A094214.

A107435 Triangle T(n,k), 1<=k<=n, read by rows: T(n,k) = length of Euclidean algorithm starting with n and k.

Original entry on oeis.org

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

Views

Author

Philippe Deléham, Jun 09 2005

Keywords

Comments

Consequence of theorem of Gabriel Lamé (1844): the first value of m in this triangle is T(F(m+2), F(m+1)) where F(n) = A000045(n); example: the first 5 is T(F(7), F(6)) = T(13, 8).
From Bernard Schott, May 01 2022: (Start)
Theorem of Gabriel Lamé (1844): The number of divisions necessary to find the greatest common divisor of two natural numbers n > k by means of the Euclidean algorithm is never greater than five times the number of digits of the smaller number k (see link).
This upper bound 5*length(k) is the best possible; the smallest pairs (n, k) for which T(n, k) = 5 * length(k) when length(k) = 1, 2 or 3 are respectively (F(7), F(6)), (F(12), F(11)) and (F(17), F(16)) where F(n) = A000045(n). This upper bound is not attained when length(k) >= 4. (End)

Examples

			13 = 5*2 + 3, 5 = 3*1 + 2, 3 = 2*1 + 1, 2 = 2*1 + 0 = so that T(13,5) = 4.
Triangle begins:
  1
  1 1
  1 2 1
  1 1 2 1
  1 2 3 2 1
  1 1 1 2 2 1
  1 2 2 3 3 2 1
  1 1 3 1 4 2 2 1
  1 2 1 2 3 2 3 2 1
  1 1 2 2 1 3 3 2 2 1
  1 2 3 3 2 3 4 4 3 2 1
  1 1 1 1 3 1 4 2 2 2 2 1
  1 2 2 2 4 2 3 5 3 3 3 2 1
  1 1 3 2 3 2 1 3 4 3 4 2 2 1
  1 2 1 3 1 2 2 3 3 2 4 2 3 2 1
  1 1 2 1 2 3 3 1 4 4 3 2 3 2 2 1
  1 2 3 2 3 3 3 2 3 4 4 4 3 4 3 2 1
  ..............................
Smallest examples with T(n, k) = 5 * length(k) (Theorem of Gabriel Lamé):
13 = 8*1 + 5, 8 = 5*1 + 3, 5 = 3*1 + 2, 3 = 2*1 + 1, 2 = 2*1 + 0 = so that T(13,8) = 5 = 5 * length(8).
144 = 89*1 + 55, 89 = 55*1 + 34, 55 = 34*1 + 21, 34 = 21*1 + 13, 21 = 13*1 + 8, then 5 steps already seen in the previous example, so that T(144,89) = 10 = 5 * length(89).
1597 = 987*1 + 610, 987 = 610*1 + 377, 610 = 377*1 + 233, 377 = 233*1 + 144, 233 = 144*1 + 89, then 10 steps already seen in the previous examples, so that T(1597,987) = 15 = 5 * length(987).
		

References

  • Ross Honsberger, Mathematical Gems II, Dolciani Mathematical Expositions No. 2, Mathematical Association of America, 1976, Chapter 7, A Theorem of Gabriel Lamé, pp. 54-57.
  • Wacław Sierpiński, Elementary Theory of Numbers, Theorem 12 (Lamé) p. 21, Warsaw, 1964.

Crossrefs

Programs

  • Maple
    F:= proc(n,k) option remember;
       if n mod k = 0 then 1
       else 1 + procname(k, n mod k)
       fi
    end proc:
    seq(seq(F(n,k),k=1..n), n=1..15); # Robert Israel, Feb 16 2016
  • Mathematica
    T[n_, k_] := T[n, k] = If[Divisible[n, k], 1, 1 + T[k, Mod[n, k]]];
    Table[T[n, k], {n, 1, 15}, {k, 1, n}] // Flatten (* Jean-François Alcover, Apr 12 2019, after Robert Israel *)
  • PARI
    T(n, k) = if ((n % k) == 0, 1, 1 + T(k, n % k)); \\ Michel Marcus, May 02 2022

Formula

T(n, k) = A049816(n, k) + 1.
From Robert Israel, Feb 16 2016: (Start)
T(n, k) = 1 if n == 0 (mod k), otherwise T(n, k) = 1 + T(k, (n mod k)).
G.f. G(x,y) of triangle satisfies G(x,y) = x*y/((1-x)*(1-x*y)) - Sum_{k>=1} (x^2*y)^k/(1-x^k) + Sum_{k>=1} G(x^k*y,x). (End)
From Bernard Schott, Apr 29 2022: (Start)
T(F(m+2), F(m+1)) = m where F(n) = A000045(n) (first comment).
T(n, k) <= 5 * length(k) where length(k) = A055642(k).
T(n, k) <= 1 + floor(log(k)/log(phi)) where log(phi) = A002390; the least numbers for which equality stands are when k and n are consecutive Fibonacci numbers. (End)

A051011 Numerator of average of number of steps in Euclidean algorithm for all gcd(m,n) with 0<=m

Original entry on oeis.org

0, 1, 1, 1, 8, 7, 13, 7, 16, 17, 27, 5, 32, 31, 31, 17, 46, 41, 55, 11, 50, 5, 73, 9, 68, 73, 25, 18, 96, 71, 101, 45, 32, 105, 101, 23, 124, 119, 41, 11, 146, 113, 155, 3, 44, 151, 177, 23, 164, 161, 169, 41, 204, 167, 183, 83, 64, 201, 231, 44, 240, 223, 209, 109
Offset: 1

Views

Author

Keywords

Crossrefs

Cf. A034883, A051010, A051012 (denominators).

Programs

  • Haskell
    import Data.Ratio ((%), numerator)
    a051011 n = numerator $ (sum $ a051010_row n) % n
    -- Reinhard Zumkeller, Jun 27 2013
  • Mathematica
    t[m_, n_] := For[r[-1]=m; r[0]=n; k=1, True, k++, r[k] = Mod[r[k-2], r[k-1]]; If[r[k] == 0, Return[k-1]]]; a[n_] := Numerator[Sum[t[m, n], {m, 0, n}]/n]; Array[a, 100] (* Amiram Eldar, Apr 22 2022 after Jean-François Alcover at A051010 *)

A051012 Denominator of average of number of steps in Euclidean algorithm for all gcd(m,n) with 0 <= m < n.

Original entry on oeis.org

1, 2, 1, 1, 5, 6, 7, 4, 9, 10, 11, 3, 13, 14, 15, 8, 17, 18, 19, 5, 21, 2, 23, 4, 25, 26, 9, 7, 29, 30, 31, 16, 11, 34, 35, 9, 37, 38, 13, 4, 41, 42, 43, 1, 15, 46, 47, 8, 49, 50, 51, 13, 53, 54, 55, 28, 19, 58, 59, 15, 61, 62, 63, 32, 65, 6, 67, 17, 69, 70, 71, 36, 73, 74, 75
Offset: 1

Views

Author

Keywords

Crossrefs

Cf. A034883, A051010, A051011 (numerators).

Programs

  • Haskell
    import Data.Ratio ((%), denominator)
    a051012 n = denominator $ (sum $ a051010_row n) % n
    -- Reinhard Zumkeller, Jun 27 2013
  • Mathematica
    t[m_, n_] := For[r[-1]=m; r[0]=n; k=1, True, k++, r[k] = Mod[r[k-2], r[k-1]]; If[r[k] == 0, Return[k-1]]]; a[n_] := Denominator[Sum[t[m, n], {m, 0, n}]/n]; Array[a, 100] (* Amiram Eldar, Apr 22 2022 after Jean-François Alcover at A051010 *)

A071647 a(n) is the maximum number of elements among the continued fractions for n/1, n/2, n/3, n/4, ..., n/n.

Original entry on oeis.org

1, 1, 2, 2, 3, 2, 3, 4, 3, 3, 4, 4, 5, 4, 4, 4, 4, 5, 5, 4, 6, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 5, 5, 7, 5, 5, 6, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 6, 7, 7, 6, 6, 6, 5, 8, 6, 6, 6, 6, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 6, 7, 6, 7, 7, 7, 8, 6, 6, 8, 8, 8, 7, 7, 6, 7, 7, 7
Offset: 1

Views

Author

Benoit Cloitre, Jun 22 2002

Keywords

Comments

a(n)/log(n) is bounded.
Apart from initial term, same as A034883. - Franklin T. Adams-Watters, Nov 14 2006

Examples

			Continued fractions for 5/1 = [5]; 5/2 = [2, 2]; 5/3 = [1, 1, 2]; 5/4 = [1, 4]; 5/5 = [1]. Hence a(5) = 3.
		

Crossrefs

Programs

  • Mathematica
    a[n_] := Max[Table[Length[ContinuedFraction[n/k]], {k, 1, n}]]; Array[a, 100] (* Amiram Eldar, Apr 19 2025 *)
  • PARI
    for(n=1,150,print1( vecmax(vector(n,i,length(contfrac(n/i)))),","))

A188224 For k > a(n), the maximum number of steps that the Euclidean algorithm requires for computing (k,i), with i < k, is greater than n.

Original entry on oeis.org

1, 2, 6, 10, 24, 54, 96, 200, 442, 650, 1548, 2370, 4060, 7670, 15792, 25740, 49074, 81900, 147756, 251012
Offset: 0

Views

Author

T. D. Noe, Mar 24 2011

Keywords

Comments

That is, A034883(k) > n for k > a(n).

Crossrefs

Cf. A034883 (maximum length of the Euclidean algorithm)

A278744 Number of steps (modular reductions) in calculating the GCD of n-th consecutive primes p(n) and p(n+1) by the Euclidean algorithm.

Original entry on oeis.org

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

Views

Author

Adnan Baysal, Nov 27 2016

Keywords

Comments

If x(0)>x(1) are integers, the Euclidean algorithm (or Euclid's algorithm) calculates the GCD of x(0) and x(1) by the recursive formula x(i+2) = x(i) mod x(i+1). This recursion terminates when x(t) = 0 for some t. Then x(t-1) is the GCD. Since the p(n) and p(n+1) are distinct primes, their GCD is 1, and there corresponding x(t-1) = 1. a(n) is the number of modular reductions, i.e., t-2.
Records are a(1) = 1 from gcd(2,3), a(2) = 2 from gcd(3,5), a(4) = 3 from gcd(7, 11), a(46) = 5 from gcd(199,211), a(221) = 6 from gcd(1381,1399), a(757) = 7 from gcd(5749,5779), a(5518) = 8 from gcd(54217,54251), a(65106) = 9 from gcd(815729, 815809), a(1293698) = 10 from gcd(20388583m 20388727), a(3997147) = 11 from gcd(67816457, 67816601). - Charles R Greathouse IV, Nov 28 2016

Examples

			For n=5, x(0) = p(6) = 13, x(1) = p(5) = 11. Then x(0) mod x(1) = x(2) = 2, hence x(1) mod x(2) = x(3) = 1. Since there are two modular reductions, a(5) = 2.
		

Crossrefs

Programs

  • PARI
    ctgcd(m,n)=my(s); while(n!=1, [m,n]=[n,m%n]; s++); s
    a(n,p=prime(n),q=nextprime(p+1))=ctgcd(p,q-p)+1 \\ Charles R Greathouse IV, Nov 28 2016
  • Sage
    A = []
    q = 1
    for i in range(100):
       q = next_prime(q)
       p = next_prime(q)
       ctr = 0
       while q!=1:
           r = p%q
           p = q
           q = r
           ctr += 1
       A.append(ctr)
    print A
    

A365262 Numbers k which never require the maximum number of steps for the Euclidean algorithm to compute gcd(k,m) for any m > k.

Original entry on oeis.org

54, 78, 96, 135, 150, 156, 164, 182, 252, 304, 336, 442, 480, 483, 525, 532, 558, 570, 582, 640, 645, 675, 740, 744, 780, 912, 918, 922, 924, 1012, 1046, 1132, 1155, 1164, 1170, 1206, 1218, 1320, 1422, 1424, 1450, 1452, 1456, 1488, 1496, 1536, 1548, 1568, 1594
Offset: 1

Views

Author

John Metcalf, Aug 29 2023

Keywords

Examples

			k = 54 is a term as the number of steps required to compute the Euclidean algorithm gcd(k, m) is smaller than A034883(m) for all m > k.
k = 27 is not a term as the number of steps required to compute the Euclidean algorithm gcd(k, m) is equal to A034883(m) for m = 35 (steps = 5), 44 (steps = 6) and 46 (steps = 6).
		

Crossrefs

Programs

  • Ruby
    def gcdsteps(k, m)
      k.zero? ? 0 : 1 + gcdsteps(m % k, k)
    end
    flags = [nil, *1..5000]
    (1..flags.length).each do |m|
      scores = []
      (1..m).each do |k|
        scores << [gcdsteps(k, m), k]
      end
      scores.sort_by! { |n| n[0] }
      scores.select { |n| n[0] == scores.last[0] }.each do |n|
        flags[n[1]] = nil
      end
    end
    print flags[1..flags.length / 2].compact
Showing 1-9 of 9 results.