Kaprekar's routine

TheoremStructure of four-digit Kaprekar dynamics in odd bases#✓fully proved

Let \(B > 3\) be an odd integer. For a pair of natural numbers \(d = (d_1, d_2)\), let \(K(d) = (a - e, b - c)\), where \(a \ge b \ge c \ge e\) are the four numbers \(d_1 - 1, B - 1, B - 1, B - d_1\) if \(d_2 = 0\), and \(d_1, d_2 - 1, B - d_2 - 1, B - d_1\) if \(d_2 \ne 0\), sorted in decreasing order (subtraction is truncated at \(0\)). Let \(X_B\) be the set of pairs with \(1 \le d_1 < B\) and \(d_2 \le d_1\), and let \(T_B\) be the set of pairs in \(X_B\) with \(0 < d_2 < d_1\) and \(d_1\), \(d_2\) both odd. Let \(\mathcal{P}\) be the set of two-element sets \(S\) of subsets of \(\mathbb{Z}/B\mathbb{Z}\) such that every \(C \in S\) has the form \(\{x, -x\}\) with \(x \ne 0\). For a set \(S\) of subsets of \(\mathbb{Z}/B\mathbb{Z}\) let \(2S = \{2C : C \in S\}\), where \(2C = \{2y : y \in C\}\), and for \(d \in T_B\) let \(\Phi(d) = \{\{u, -u\}, \{v, -v\}\}\), where \(u\) and \(v\) are the residues of \((d_1 + d_2)/2\) and \((d_1 - d_2)/2\) modulo \(B\). Then \(K\) maps \(T_B\) into itself, the third iterate \(K^3\) maps \(X_B\) into \(T_B\), \(S \mapsto 2S\) maps \(\mathcal{P}\) into itself, \(\Phi\) is a bijection from \(T_B\) onto \(\mathcal{P}\), and \(\Phi(K(d)) = 2\,\Phi(d)\) for every \(d \in T_B\).

Here a pair \((d_1, d_2) \in X_B\) stands for the four-digit base-\(B\) numbers whose digits, sorted as \(a \ge b \ge c \ge e\), satisfy \(a - e = d_1\) and \(b - c = d_2\); the four numbers listed above are the base-\(B\) digits of their Kaprekar image, so \(K\) is the Kaprekar map on these pairs.

theorem four_digit_kaprekar_structural_classification
    (B : ℕ) (hB : Odd B) (hB3 : 3 < B) :
    let X_B : Set (ℕ × ℕ) :=
      {d | 1 ≤ d.1 ∧ d.1 < B ∧ d.2 ≤ d.1};
    let T_B : Set (ℕ × ℕ) :=
      {d | d ∈ X_B ∧ d.2 < d.1 ∧ 0 < d.2 ∧ Odd d.1 ∧ Odd d.2};
    let kaprekar : ℕ × ℕ → ℕ × ℕ := fun d =>
      match List.insertionSort (· ≥ ·)
        (if d.2 = 0 then [d.1 - 1, B - 1, B - 1, B - d.1]
          else [d.1, d.2 - 1, B - d.2 - 1, B - d.1]) with
Sources

DefinitionKaprekar difference#✓fully proved

Let \(l\) be a list of \(k\) natural numbers and let \(a_0 \le a_1 \le \dots \le a_{k-1}\) be its entries in increasing order. The Kaprekar difference of \(l\) is \(\alpha_M - \alpha_L\), where \(\alpha_M = \sum_{i\lt k} a_i 10^i\) and \(\alpha_L = \sum_{i\lt k} a_{k-1-i} 10^i\). When the entries are decimal digits, \(\alpha_M\) is the number written with the digits of \(l\) in descending order and \(\alpha_L\) is the number written with them in ascending order (leading zeros allowed).

public def kaprekarDiff (l : List ℕ) : ℕ :=
  Nat.ofDigits 10 (List.insertionSort (· ≤ ·) l) - Nat.ofDigits 10 (List.insertionSort (· ≥ ·) l)
Sources
  • Haruo Iwasaki, A New Classification of the Kaprekar Numbers, The Fibonacci Quarterly 62 (2024), Article iwasaki06162024-ASrev2, Definition 1.1.
Used by 2

DefinitionKaprekar map#✓fully proved

For natural numbers \(n\) and \(\alpha\), take the decimal digits of \(\alpha\) (without leading zeros, and no digits at all for \(\alpha = 0\)) and, if there are fewer than \(n\) of them, pad them with leading zeros to a string of exactly \(n\) digits. The Kaprekar map sends \(\alpha\) to the Kaprekar difference \(\alpha_M - \alpha_L\) of this digit string: the number with these digits in descending order minus the number with them in ascending order. For \(\alpha < 10^n\) this is the Kaprekar transformation on the set \(D_n\) of \(n\)-digit strings; for \(\alpha \ge 10^n\) nothing is padded and all digits of \(\alpha\) are used.

public def kaprekarMap (n α : ℕ) : ℕ :=
  kaprekarDiff (Nat.digits 10 α ++ List.replicate (n - (Nat.digits 10 α).length) 0)
Sources
  • Haruo Iwasaki, A New Classification of the Kaprekar Numbers, The Fibonacci Quarterly 62 (2024), Article iwasaki06162024-ASrev2, Definition 1.1.
Uses 1 · Used by 4

Theorem6174 is fixed by the four-digit Kaprekar map#✓fully proved

The Kaprekar map with \(n = 4\) sends \(6174\) to itself: \(7641 - 1467 = 6174\).

public theorem kaprekarMap_four_6174 : kaprekarMap 4 6174 = 6174
Sources
  • Haruo Iwasaki, A New Classification of the Kaprekar Numbers, The Fibonacci Quarterly 62 (2024), Article iwasaki06162024-ASrev2, Section 1.
Uses 1
Statement usesKaprekar map

Theorem495 is fixed by the three-digit Kaprekar map#✓fully proved

The Kaprekar map with \(n = 3\) sends \(495\) to itself: \(954 - 459 = 495\).

public theorem kaprekarMap_three_495 : kaprekarMap 3 495 = 495
Sources
  • Haruo Iwasaki, A New Classification of the Kaprekar Numbers, The Fibonacci Quarterly 62 (2024), Article iwasaki06162024-ASrev2, Section 1.
Uses 1
Statement usesKaprekar map

TheoremThe four-digit Kaprekar map sends 495 to 9081#✓fully proved

With \(n = 4\), the number \(495\) is padded to the digit string \(0495\), and the Kaprekar map sends it to \(9540 - 0459 = 9081\).

public theorem kaprekarMap_four_495 : kaprekarMap 4 495 = 9081
Sources
  • Haruo Iwasaki, A New Classification of the Kaprekar Numbers, The Fibonacci Quarterly 62 (2024), Article iwasaki06162024-ASrev2, Definition 1.1.
Uses 1
Statement usesKaprekar map

TheoremClassification of decimal Kaprekar numbers#●ready to prove

Let \(n \ge 3\) and \(0 < \alpha < 10^n\). Then the Kaprekar map on \(n\)-digit strings fixes \(\alpha\) if and only if \(\alpha\) is the Kaprekar difference of some string \(s\) of exactly \(n\) decimal digits of one of the following five forms, where juxtaposition is concatenation, \((w)^k\) is the block \(w\) repeated \(k\) times, and in each form the exponents are chosen independently with \(x, x_1, x_2 \ge 1\) and \(y, y_1, y_2 \ge 0\): \((495)^x\); \(6174\,(36)^y\); \((123456789)^x (36)^y\); \((123456789)^{x_1} (36)^{x_2} (495)^{2x_2} (27)^{3x_2}\); \((124578)^{x_1} (09)^{x_2} (123456789)^{y_1} (36)^{y_2}\).

The witness string must have length \(n\): \(495\) is the Kaprekar difference of \((495)^1\), but the Kaprekar map on \(4\)-digit strings sends \(495\) to \(9081\).

MetaMathlibExt.kaprekarMap_fixed_iff · 17 lines
public theorem_wanted kaprekarMap_fixed_iff {n α : ℕ} (hn : 3 ≤ n) (hα : α < 10 ^ n)
    (hα0 : α ≠ 0) :
    kaprekarMap n α = α ↔
      ∃ s : List ℕ, s.length = n ∧ kaprekarDiff s = α ∧
        ((∃ x, 1 ≤ x ∧ s = (List.replicate x [4, 9, 5]).flatten) ∨
          (∃ y, s = [6, 1, 7, 4] ++ (List.replicate y [3, 6]).flatten) ∨
          (∃ x y, 1 ≤ x ∧ s = (List.replicate x [1, 2, 3, 4, 5, 6, 7, 8, 9]).flatten ++
            (List.replicate y [3, 6]).flatten) ∨
          (∃ x₁ x₂, 1 ≤ x₁ ∧ 1 ≤ x₂ ∧
            s = (List.replicate x₁ [1, 2, 3, 4, 5, 6, 7, 8, 9]).flatten ++
              (List.replicate x₂ [3, 6]).flatten ++ (List.replicate (2 * x₂) [4, 9, 5]).flatten ++
              (List.replicate (3 * x₂) [2, 7]).flatten) ∨
          (∃ x₁ x₂ y₁ y₂, 1 ≤ x₁ ∧ 1 ≤ x₂ ∧
            s = (List.replicate x₁ [1, 2, 4, 5, 7, 8]).flatten ++
              (List.replicate x₂ [0, 9]).flatten ++
              (List.replicate y₁ [1, 2, 3, 4, 5, 6, 7, 8, 9]).flatten ++
              (List.replicate y₂ [3, 6]).flatten))
Sources
  • Haruo Iwasaki, A New Classification of the Kaprekar Numbers, The Fibonacci Quarterly 62 (2024), Article iwasaki06162024-ASrev2, Theorem 3.1.
Uses 2

DefinitionThe four-digit Kaprekar map in difference coordinates#✓fully proved

For a base \(B\) and a pair of natural numbers \((d_1, d_2)\), the map \(K_B\) forms the list of four digits \([d_1 - 1, B - 1, B - 1, B - d_1]\) if \(d_2 = 0\) and \([d_1, d_2 - 1, B - d_2 - 1, B - d_1]\) if \(d_2 > 0\), sorts it decreasingly as \(a_1 \ge a_2 \ge a_3 \ge a_4\), and sets \(K_B(d_1, d_2) = (a_1 - a_4, a_2 - a_3)\). Subtraction of natural numbers is truncated at \(0\); for \(1 \le d_1 < B\) and \(0 \le d_2 \le d_1\) no truncation occurs.

For such \((d_1, d_2)\) the list holds the digits of the Kaprekar difference (largest minus smallest arrangement) of any four-digit base-\(B\) string with difference coordinates \((d_1, d_2)\), as in paper displays (5) and (6).

public def kaprekarFourDigitStep (B : ℕ) (d : ℕ × ℕ) : ℕ × ℕ :=
  match List.insertionSort (· ≥ ·)
    (if d.2 = 0 then [d.1 - 1, B - 1, B - 1, B - d.1]
      else [d.1, d.2 - 1, B - d.2 - 1, B - d.1]) with
  | [a, b, c, e] => (a - e, b - c)
  | _ => (0, 0)
Sources
  • Evan Chen, Ken Ono, Richard E. Schwartz, and Dinesh Thakur, Four-Digit Kaprekar Dynamics in Odd Bases, Journal of Integer Sequences 29 (2026), Article 26.4.7, Section 2.1.
Used by 7

TheoremSample values of the four-digit Kaprekar map#✓fully proved

The four-digit Kaprekar map satisfies \(K_{11}(5, 1) = (9, 1)\), \(K_{11}(6, 0) = (5, 5)\) and \(K_{11}(5, 5) = (2, 0)\) in base \(11\), and \(K_7(3, 1) = (5, 1)\), \(K_7(5, 1) = (5, 3)\) and \(K_7(5, 3) = (3, 1)\) in base \(7\).

In particular \((3, 1) \mapsto (5, 1) \mapsto (5, 3) \mapsto (3, 1)\) is a terminal cycle of \(K_7\).

public theorem kaprekarFourDigitStep_examples :
    kaprekarFourDigitStep 11 (5, 1) = (9, 1) ∧ kaprekarFourDigitStep 11 (6, 0) = (5, 5) ∧
      kaprekarFourDigitStep 11 (5, 5) = (2, 0) ∧ kaprekarFourDigitStep 7 (3, 1) = (5, 1) ∧
      kaprekarFourDigitStep 7 (5, 1) = (5, 3) ∧ kaprekarFourDigitStep 7 (5, 3) = (3, 1)
Sources
  • Evan Chen, Ken Ono, Richard E. Schwartz, and Dinesh Thakur, Four-Digit Kaprekar Dynamics in Odd Bases, Journal of Integer Sequences 29 (2026), Article 26.4.7, Examples 7, 12 and 18.
Uses 1

DefinitionThe four-digit Kaprekar state space#✓fully proved

For a base \(B\), the state space \(X_B\) is the finite set of pairs of natural numbers \((d_1, d_2)\) with \(1 \le d_1 < B\) and \(0 \le d_2 \le d_1\).

A nonconstant four-digit base-\(B\) string with sorted digits \(a_1 \ge a_2 \ge a_3 \ge a_4\) has difference coordinates \((d_1, d_2) = (a_1 - a_4, a_2 - a_3)\), a point of \(X_B\).

public def kaprekarFourDigitStates (B : ℕ) : Finset (ℕ × ℕ) :=
  (Finset.range B ×ˢ Finset.range B).filter fun d => 1 ≤ d.1 ∧ d.2 ≤ d.1
Sources
  • Evan Chen, Ken Ono, Richard E. Schwartz, and Dinesh Thakur, Four-Digit Kaprekar Dynamics in Odd Bases, Journal of Integer Sequences 29 (2026), Article 26.4.7, display (2).
Used by 7

TheoremSizes of the Kaprekar state spaces in bases 3 and 7#✓fully proved

The four-digit Kaprekar state spaces satisfy \(|X_3| = 5\) and \(|X_7| = 27\).

Both values agree with the general count \(|X_B| = (B - 1)(B + 2)/2\).

public theorem kaprekarFourDigitStates_card_examples :
    (kaprekarFourDigitStates 3).card = 5 ∧ (kaprekarFourDigitStates 7).card = 27
Sources
  • Evan Chen, Ken Ono, Richard E. Schwartz, and Dinesh Thakur, Four-Digit Kaprekar Dynamics in Odd Bases, Journal of Integer Sequences 29 (2026), Article 26.4.7, display (2) and the proof of Corollary 27.
Uses 1

DefinitionProjective order of 2#✓fully proved

For a natural number \(n\), the projective order of \(2\) modulo \(n\) is the least \(m > 0\) with \(2^m \equiv 1\) or \(2^m \equiv -1 \pmod{n}\),

\[\lambda(n) = \min \{m > 0 : 2^m \equiv \pm 1 \pmod{n}\},\]

and \(\lambda(n) = 0\) when no such \(m\) exists, which happens exactly when \(n\) is even (including \(n = 0\), where congruence modulo \(0\) is equality of integers). For odd \(n\) these are the terms of OEIS A003558, which lists \(\lambda(2k + 1)\) at index \(k\).

public noncomputable def projectiveOrderTwo (n : ℕ) : ℕ :=
  sInf {m : ℕ | 0 < m ∧ ((2 : ZMod n) ^ m = 1 ∨ (2 : ZMod n) ^ m = -1)}
Sources
  • Evan Chen, Ken Ono, Richard E. Schwartz, and Dinesh Thakur, Four-Digit Kaprekar Dynamics in Odd Bases, Journal of Integer Sequences 29 (2026), Article 26.4.7, Definition 19, display (13).
Used by 7

TheoremCharacterization of the projective order of 2#✓fully proved

Let \(n\) and \(m\) be natural numbers with \(m > 0\). Suppose that \(2^m \equiv 1\) or \(2^m \equiv -1 \pmod{n}\), and that for every \(k\) with \(0 < k < m\) neither \(2^k \equiv 1\) nor \(2^k \equiv -1 \pmod{n}\). Then the projective order of \(2\) modulo \(n\) is \(\lambda(n) = m\).

public theorem projectiveOrderTwo_eq_of {n m : ℕ} (hm : 0 < m)
    (h : (2 : ZMod n) ^ m = 1 ∨ (2 : ZMod n) ^ m = -1)
    (hmin : ∀ k < m, 0 < k → (2 : ZMod n) ^ k ≠ 1 ∧ (2 : ZMod n) ^ k ≠ -1) :
    projectiveOrderTwo n = m
Sources
  • Evan Chen, Ken Ono, Richard E. Schwartz, and Dinesh Thakur, Four-Digit Kaprekar Dynamics in Odd Bases, Journal of Integer Sequences 29 (2026), Article 26.4.7, Definition 19, display (13).
Uses 1 · Used by 1

TheoremValues of the projective order of 2#✓fully proved

Writing \(\lambda(n)\) for the projective order of \(2\) modulo \(n\), we have \(\lambda(7) = 3\), \(\lambda(9) = 3\), \(\lambda(11) = 5\) and \(\lambda(17) = 4\).

public theorem projectiveOrderTwo_examples :
    projectiveOrderTwo 7 = 3 ∧ projectiveOrderTwo 9 = 3 ∧ projectiveOrderTwo 11 = 5 ∧
      projectiveOrderTwo 17 = 4
Sources
  • Evan Chen, Ken Ono, Richard E. Schwartz, and Dinesh Thakur, Four-Digit Kaprekar Dynamics in Odd Bases, Journal of Integer Sequences 29 (2026), Article 26.4.7, Examples 7-10 and 23.
Uses 2

TheoremCycle lengths of doubling on pairs of projective classes#●ready to prove

Let \(B > 3\) be odd. For \(x \in \mathbb{Z}/B\mathbb{Z}\) write \([x] = \{x, -x\}\) and \(2C = \{2c : c \in C\}\) for a subset \(C\) of \(\mathbb{Z}/B\mathbb{Z}\), and let \(D\) be the doubling map sending a set \(T\) of subsets of \(\mathbb{Z}/B\mathbb{Z}\) to \(\{2C : C \in T\}\). If \(S = \{[r], [s]\}\) for nonzero \(r, s \in \mathbb{Z}/B\mathbb{Z}\) with \([r] \ne [s]\), then \(S\) is a periodic point of \(D\) and its minimal period is at most \(\lambda(B)\), the projective order of \(2\) modulo \(B\).

public theorem_wanted projective_doubling_minimalPeriod_le_projectiveOrderTwo (B : ℕ)
    (hB : Odd B) (hB3 : 3 < B) (S : Finset (Finset (ZMod B)))
    (hS : S.card = 2 ∧ ∀ C ∈ S, ∃ x : ZMod B, x ≠ 0 ∧ C = {x, -x}) :
    0 < Function.minimalPeriod
        (fun T : Finset (Finset (ZMod B)) => T.image fun C => C.image (· * 2)) S ∧
      Function.minimalPeriod
        (fun T : Finset (Finset (ZMod B)) => T.image fun C => C.image (· * 2)) S ≤
        projectiveOrderTwo B
Sources
  • Evan Chen, Ken Ono, Richard E. Schwartz, and Dinesh Thakur, Four-Digit Kaprekar Dynamics in Odd Bases, Journal of Integer Sequences 29 (2026), Article 26.4.7, Lemma 20 (jis-2026-26.4.7-lem-20).
Uses 1
Statement usesProjective order of 2

TheoremProjective order of 2 is at most half the totient#●ready to prove

For every odd natural number \(B > 3\), the projective order of \(2\) modulo \(B\) satisfies \(\lambda(B) \le \lfloor \varphi(B)/2 \rfloor\), where \(\varphi\) is Euler's totient function.

public theorem_wanted projectiveOrderTwo_le_totient_div_two (B : ℕ) (hB : Odd B)
    (hB3 : 3 < B) :
    projectiveOrderTwo B ≤ B.totient / 2
Sources
  • Evan Chen, Ken Ono, Richard E. Schwartz, and Dinesh Thakur, Four-Digit Kaprekar Dynamics in Odd Bases, Journal of Integer Sequences 29 (2026), Article 26.4.7, Lemma 21 (quoting Kay and Downes-Ward, Theorem 2) (jis-2026-26.4.7-lem-21).
Uses 1
Statement usesProjective order of 2

TheoremLong Kaprekar cycles force a prime base#●ready to prove

Let \(B > 3\) be odd, let \(K_B\) be the four-digit Kaprekar map and \(X_B\) its state space. Every point of \(X_B\) that is periodic for \(K_B\) has minimal period at most \((B - 1)/2\), and if some point of \(X_B\) has minimal period exactly \((B - 1)/2\) under \(K_B\), then \(B\) is prime.

public theorem_wanted kaprekar_minimalPeriod_le_and_prime_of_eq (B : ℕ) (hB : Odd B)
    (hB3 : 3 < B) :
    (∀ d ∈ kaprekarFourDigitStates B, d ∈ Function.periodicPts (kaprekarFourDigitStep B) →
      Function.minimalPeriod (kaprekarFourDigitStep B) d ≤ (B - 1) / 2) ∧
      ((∃ d ∈ kaprekarFourDigitStates B,
          Function.minimalPeriod (kaprekarFourDigitStep B) d = (B - 1) / 2) → B.Prime)
Sources
  • Evan Chen, Ken Ono, Richard E. Schwartz, and Dinesh Thakur, Four-Digit Kaprekar Dynamics in Odd Bases, Journal of Integer Sequences 29 (2026), Article 26.4.7, Corollary 22 (jis-2026-26.4.7-cor-22).
Uses 2

TheoremMaximal Kaprekar cycle length in odd bases#●ready to prove

Let \(B > 3\) be odd, let \(K_B\) be the four-digit Kaprekar map and \(X_B\) its state space, and let \(\lambda(B)\) be the projective order of \(2\) modulo \(B\). Every point of \(X_B\) that is periodic for \(K_B\) has minimal period at most \((B - 1)/2\). Moreover, some point of \(X_B\) has minimal period exactly \((B - 1)/2\) under \(K_B\) if and only if \(B \ge 7\), \(B\) is prime and \(\lambda(B) = (B - 1)/2\).

public theorem_wanted kaprekar_minimalPeriod_le_and_eq_iff (B : ℕ) (hB : Odd B)
    (hB3 : 3 < B) :
    (∀ d ∈ kaprekarFourDigitStates B, d ∈ Function.periodicPts (kaprekarFourDigitStep B) →
      Function.minimalPeriod (kaprekarFourDigitStep B) d ≤ (B - 1) / 2) ∧
      ((∃ d ∈ kaprekarFourDigitStates B,
          Function.minimalPeriod (kaprekarFourDigitStep B) d = (B - 1) / 2) ↔
        7 ≤ B ∧ B.Prime ∧ projectiveOrderTwo B = (B - 1) / 2)
Sources
  • Evan Chen, Ken Ono, Richard E. Schwartz, and Dinesh Thakur, Four-Digit Kaprekar Dynamics in Odd Bases, Journal of Integer Sequences 29 (2026), Article 26.4.7, Corollary 3 (jis-2026-26.4.7-cor-3).
Uses 3

TheoremNumber of Kaprekar cycles of maximal length#●ready to prove

Let \(B > 3\) be odd, let \(K_B\) be the four-digit Kaprekar map and \(X_B\) its state space, and put \(q = (B - 1)/2\). If some point of \(X_B\) has minimal period \(q\) under \(K_B\), then exactly \(q \lfloor (q - 1)/2 \rfloor\) points of \(X_B\) have minimal period \(q\) under \(K_B\).

Equivalently, \(K_B\) then has exactly \(\lfloor (q - 1)/2 \rfloor\) terminal cycles of length \(q\) on \(X_B\).

public theorem_wanted kaprekar_card_maximal_cycles (B : ℕ) (hB : Odd B) (hB3 : 3 < B)
    (heq : ∃ d ∈ kaprekarFourDigitStates B,
      Function.minimalPeriod (kaprekarFourDigitStep B) d = (B - 1) / 2) :
    ((kaprekarFourDigitStates B).filter fun d =>
        Function.minimalPeriod (kaprekarFourDigitStep B) d = (B - 1) / 2).card =
      (B - 1) / 2 * (((B - 1) / 2 - 1) / 2)
Sources
  • Evan Chen, Ken Ono, Richard E. Schwartz, and Dinesh Thakur, Four-Digit Kaprekar Dynamics in Odd Bases, Journal of Integer Sequences 29 (2026), Article 26.4.7, Corollary 5 (jis-2026-26.4.7-cor-5).
Uses 2

TheoremExplicit count of Kaprekar cycles of each length#●ready to prove

Let \(B > 3\) be odd and \(L \ge 1\), let \(K_B\) be the four-digit Kaprekar map and \(X_B\) its state space, let \(\varphi\) be Euler's totient function, and let \(\lambda(n)\) denote the projective order of \(2\) modulo \(n\). For \(a \ge 1\) put

\[\mu_B(a) = \sum_{n \mid B,\ n > 1,\ \lambda(n) = a} \left\lfloor \frac{\varphi(n)}{2a} \right\rfloor\]

and

\[N_B(L) = \mu_B(L) \left\lfloor \frac{L - 1}{2} \right\rfloor + \mu_B(2L) + \binom{\mu_B(L)}{2} L + \sum_{a, b \mid L,\ a < b,\ \operatorname{lcm}(a, b) = L} \mu_B(a)\, \mu_B(b) \gcd(a, b),\]

where \(n\) ranges over positive divisors of \(B\) and \(a, b\) in the last sum range over positive divisors of \(L\). Then exactly \(L \cdot N_B(L)\) points of \(X_B\) have minimal period \(L\) under \(K_B\).

Here \(N_B(L)\) is the number of terminal cycles of length \(L\) of \(K_B\) on \(X_B\).

public theorem_wanted kaprekar_card_minimalPeriod_eq (B : ℕ) (hB : Odd B) (hB3 : 3 < B)
    (L : ℕ) (hL : 0 < L) :
    let μ : ℕ → ℕ := fun a =>
      ∑ n ∈ B.divisors with 1 < n ∧ projectiveOrderTwo n = a, n.totient / (2 * a)
    ((kaprekarFourDigitStates B).filter fun d =>
        Function.minimalPeriod (kaprekarFourDigitStep B) d = L).card =
      L * (μ L * ((L - 1) / 2) + μ (2 * L) + (μ L).choose 2 * L +
        ∑ p ∈ (L.divisors ×ˢ L.divisors).filter (fun p => p.1 < p.2 ∧ Nat.lcm p.1 p.2 = L),
          μ p.1 * μ p.2 * Nat.gcd p.1 p.2)
Sources
  • Evan Chen, Ken Ono, Richard E. Schwartz, and Dinesh Thakur, Four-Digit Kaprekar Dynamics in Odd Bases, Journal of Integer Sequences 29 (2026), Article 26.4.7, Theorem 24, with μ_B from display (14) (jis-2026-26.4.7-thm-24).
Uses 3

TheoremAt least two Kaprekar cycles whose length is the projective order of 2#●ready to prove

Let \(\lambda(B)\) denote the projective order of \(2\) modulo \(B\). For every odd base \(B > 17\), at least \(2\lambda(B)\) points of the state space \(X_B\) have minimal period exactly \(\lambda(B)\) under the four-digit Kaprekar map \(K_B\).

Each terminal cycle of \(K_B\) of length \(\lambda(B)\) consists of \(\lambda(B)\) such points, so this says that \(K_B\) has at least two terminal cycles of length \(\lambda(B)\).

public theorem_wanted two_mul_projectiveOrderTwo_le_card_kaprekar_cycles (B : ℕ)
    (hB : Odd B) (hB3 : 17 < B) :
    2 * projectiveOrderTwo B ≤
      ((kaprekarFourDigitStates B).filter fun d =>
        Function.minimalPeriod (kaprekarFourDigitStep B) d = projectiveOrderTwo B).card
Sources
  • Evan Chen, Ken Ono, Richard E. Schwartz, and Dinesh Thakur, Four-Digit Kaprekar Dynamics in Odd Bases, Journal of Integer Sequences 29 (2026), Article 26.4.7, Corollary 27 (i) (jis-2026-26.4.7-cor-27).
Uses 3

TheoremOdd bases with a unique Kaprekar cycle#●ready to prove

Let \(B \ge 3\) be odd, let \(K_B\) be the four-digit Kaprekar map and \(X_B\) its state space. There is a point \(c \in X_B\), periodic for \(K_B\), whose forward orbit \(\{K_B^k(c) : k \ge 0\}\) contains every point of \(X_B\) that is periodic for \(K_B\), if and only if \(B \in \{3, 5, 7\}\).

That is, \(K_B\) has a unique terminal cycle on \(X_B\) exactly when \(B\) is \(3\), \(5\) or \(7\).

public theorem_wanted kaprekar_unique_cycle_iff (B : ℕ) (hB : Odd B) (hB3 : 3 ≤ B) :
    (∃ c ∈ kaprekarFourDigitStates B, c ∈ Function.periodicPts (kaprekarFourDigitStep B) ∧
      ∀ d ∈ kaprekarFourDigitStates B, d ∈ Function.periodicPts (kaprekarFourDigitStep B) →
        ∃ k, (kaprekarFourDigitStep B)^[k] c = d) ↔
      B = 3 ∨ B = 5 ∨ B = 7
Sources
  • Evan Chen, Ken Ono, Richard E. Schwartz, and Dinesh Thakur, Four-Digit Kaprekar Dynamics in Odd Bases, Journal of Integer Sequences 29 (2026), Article 26.4.7, Corollary 27 (ii) (jis-2026-26.4.7-cor-27).
Uses 2
13 fully proved9 ready to prove

The dependency explorer needs JavaScript and its graph data.

Download the complete graph data.