Kaprekar number

In mathematics, a natural number in a given number base is a $$p$$-Kaprekar number if the representation of its square in that base can be split into two parts, where the second part has $$p$$ digits, that add up to the original number. For example, in base 10, 45 is a 2-Kaprekar number, because 45² = 2025, and 20 + 25 = 45. The numbers are named after D. R. Kaprekar.

Definition and properties
Let $$n$$ be a natural number. Then the Kaprekar function for base $$b > 1$$ and power $$p > 0$$ $$F_{p, b} : \mathbb{N} \rightarrow \mathbb{N}$$ is defined to be the following:
 * $$F_{p, b}(n) = \alpha + \beta$$,

where $$\beta = n^2 \bmod b^p$$ and
 * $$\alpha = \frac{n^2 - \beta}{b^p}$$

A natural number $$n$$ is a $$p$$-Kaprekar number if it is a fixed point for $$F_{p, b}$$, which occurs if $$F_{p, b}(n) = n$$. $$0$$ and $$1$$ are trivial Kaprekar numbers for all $$b$$ and $$p$$, all other Kaprekar numbers are nontrivial Kaprekar numbers.

The earlier example of 45 satisfies this definition with $$b = 10$$ and $$p = 2$$, because
 * $$\beta = n^2 \bmod b^p = 45^2 \bmod 10^2 = 25$$
 * $$\alpha = \frac{n^2 - \beta}{b^p} = \frac{45^2 - 25}{10^2} = 20$$
 * $$F_{2, 10}(45) = \alpha + \beta = 20 + 25 = 45$$

A natural number $$n$$ is a sociable Kaprekar number if it is a periodic point for $$F_{p, b}$$, where $$F_{p, b}^k(n) = n$$ for a positive integer $$k$$ (where $$F_{p, b}^k$$ is the $$k$$th iterate of $$F_{p, b}$$), and forms a cycle of period $$k$$. A Kaprekar number is a sociable Kaprekar number with $$k = 1$$, and a amicable Kaprekar number is a sociable Kaprekar number with $$k = 2$$.

The number of iterations $$i$$ needed for $$F_{p, b}^{i}(n)$$ to reach a fixed point is the Kaprekar function's persistence of $$n$$, and undefined if it never reaches a fixed point.

There are only a finite number of $$p$$-Kaprekar numbers and cycles for a given base $$b$$, because if $$n = b^p + m$$, where $$m > 0$$ then



\begin{align} n^2 & = (b^p + m)^2 \\ & = b^{2p} + 2mb^p + m^2 \\ & = (b^p + 2m)b^p + m^2 \\ \end{align} $$

and $$\beta = m^2$$, $$\alpha = b^p + 2m$$, and $$F_{p, b}(n) = b^p + 2m + m^2 = n + (m^2 + m) > n$$. Only when $$n \leq b^p$$ do Kaprekar numbers and cycles exist.

If $$d$$ is any divisor of $$p$$, then $$n$$ is also a $$p$$-Kaprekar number for base $$b^p$$.

In base $$b = 2$$, all even perfect numbers are Kaprekar numbers. More generally, any numbers of the form $$2^n (2^{n + 1} - 1)$$ or $$2^n (2^{n + 1} + 1)$$ for natural number $$n$$ are Kaprekar numbers in base 2.

Set-theoretic definition and unitary divisors
The set $$K(N)$$ for a given integer $$N$$ can be defined as the set of integers $$X$$ for which there exist natural numbers $$A$$ and $$B$$ satisfying the Diophantine equation
 * $$X^2 = AN + B$$, where $$0 \leq B < N$$
 * $$X = A + B$$

An $$n$$-Kaprekar number for base $$b$$ is then one which lies in the set $$K(b^n)$$.

It was shown in 2000 that there is a bijection between the unitary divisors of $$N - 1$$ and the set $$K(N)$$ defined above. Let $$\operatorname{Inv}(a, c)$$ denote the multiplicative inverse of $$a$$ modulo $$c$$, namely the least positive integer $$m$$ such that $$am = 1 \bmod c$$, and for each unitary divisor $$d$$ of $$N - 1$$ let $$e = \frac{N - 1}{d}$$ and $$\zeta(d) = d\ \text{Inv}(d, e)$$. Then the function $$\zeta$$ is a bijection from the set of unitary divisors of $$N - 1$$ onto the set $$K(N)$$. In particular, a number $$X$$ is in the set $$K(N)$$ if and only if $$X = d\ \text{Inv}(d, e)$$ for some unitary divisor $$d$$ of $$N - 1$$.

The numbers in $$K(N)$$ occur in complementary pairs, $$X$$ and $$N - X$$. If $$d$$ is a unitary divisor of $$N - 1$$ then so is $$e = \frac{N - 1}{d}$$, and if $$X = d\operatorname{Inv}(d, e)$$ then $$N - X = e\operatorname{Inv}(e, d)$$.

b = 4k + 3 and p = 2n + 1
Let $$k$$ and $$n$$ be natural numbers, the number base $$b = 4k + 3 = 2(2k + 1) + 1$$, and $$p = 2n + 1$$. Then: $$
 * $$X_1 = \frac{b^p - 1}{2} = (2k + 1) \sum_{i = 0}^{p - 1} b^i$$ is a Kaprekar number.

$$
 * $$X_2 = \frac{b^p + 1}{2} = X_1 + 1$$ is a Kaprekar number for all natural numbers $$n$$.

b = m2k + m + 1 and p = mn + 1
Let $$m$$, $$k$$, and $$n$$ be natural numbers, the number base $$b = m^2k + m + 1$$, and the power $$p = mn + 1$$. Then:
 * $$X_1 = \frac{b^p - 1}{m} = (mk + 1) \sum_{i = 0}^{p - 1} b^i$$ is a Kaprekar number.
 * $$X_2 = \frac{b^p + m - 1}{m} = X_1 + 1$$ is a Kaprekar number.

b = m2k + m + 1 and p = mn + m − 1
Let $$m$$, $$k$$, and $$n$$ be natural numbers, the number base $$b = m^2k + m + 1$$, and the power $$p = mn + m - 1$$. Then:
 * $$X_1 = \frac{m(b^p - 1)}{4} = (m - 1)(mk + 1) \sum_{i = 0}^{p - 1} b^i$$ is a Kaprekar number.
 * $$X_2 = \frac{mb^p + 1}{4} = X_3 + 1$$ is a Kaprekar number.

b = m2k + m2 − m + 1 and p = mn + 1
Let $$m$$, $$k$$, and $$n$$ be natural numbers, the number base $$b = m^2k + m^2 - m + 1$$, and the power $$p = mn + m - 1$$. Then:
 * $$X_1 = \frac{(m - 1)(b^p - 1)}{m} = (m - 1)(mk + 1) \sum_{i = 0}^{p - 1} b^i$$ is a Kaprekar number.
 * $$X_2 = \frac{(m - 1)b^p + 1}{m} = X_1 + 1$$ is a Kaprekar number.

b = m2k + m2 − m + 1 and p = mn + m − 1
Let $$m$$, $$k$$, and $$n$$ be natural numbers, the number base $$b = m^2k + m^2 - m + 1$$, and the power $$p = mn + m - 1$$. Then:
 * $$X_1 = \frac{b^p - 1}{m} = (mk + 1) \sum_{i = 0}^{p - 1} b^i$$ is a Kaprekar number.
 * $$X_2 = \frac{b^p + m - 1}{m} = X_3 + 1$$ is a Kaprekar number.

Kaprekar numbers and cycles of $$F_{p, b}$$ for specific $$p$$, $$b$$
All numbers are in base $$b$$.

Extension to negative integers
Kaprekar numbers can be extended to the negative integers by use of a signed-digit representation to represent each integer.