# Narcissistic number

In number theory, a narcissistic number[1][2] (also known as a pluperfect digital invariant (PPDI),[3] an Armstrong number[4] (after Michael F. Armstrong)[5] or a plus perfect number)[6] in a given number base ${\displaystyle b}$ is a number that is the sum of its own digits each raised to the power of the number of digits.

## Definition

Let ${\displaystyle n}$ be a natural number. We define the narcissistic function for base ${\displaystyle b>1}$ ${\displaystyle F_{b}:\mathbb {N} \rightarrow \mathbb {N} }$ to be the following:

${\displaystyle F_{b}(n)=\sum _{i=0}^{k-1}d_{i}^{k}.}$

where ${\displaystyle k=\lfloor \log _{b}{n}\rfloor +1}$ is the number of digits in the number in base ${\displaystyle b}$, and

${\displaystyle d_{i}={\frac {n{\bmod {b^{i+1}}}-n{\bmod {b}}^{i}}{b^{i}}}}$

is the value of each digit of the number. A natural number ${\displaystyle n}$ is a narcissistic number if it is a fixed point for ${\displaystyle F_{b}}$, which occurs if ${\displaystyle F_{b}(n)=n}$. The natural numbers ${\displaystyle 0\leq n are trivial narcissistic numbers for all ${\displaystyle b}$, all other narcissistic numbers are nontrivial narcissistic numbers.

For example, the number 122 in base ${\displaystyle b=3}$ is a narcissistic number, because ${\displaystyle k=3}$ and ${\displaystyle 122=1^{3}+2^{3}+2^{3}}$.

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

All natural numbers ${\displaystyle n}$ are preperiodic points for ${\displaystyle F_{b}}$, regardless of the base. This is because for any given digit count ${\displaystyle k}$, the minimum possible value of ${\displaystyle n}$ is ${\displaystyle b^{k-1}}$, the maximum possible value of ${\displaystyle n}$ is ${\displaystyle b^{k}-1\leq b^{k}}$, and the narcissistic function value is ${\displaystyle F_{b}(n)=k(b-1)^{k}}$. Thus, any narcissistic number must satisfy the inequality ${\displaystyle b^{k-1}\leq k(b-1)^{k}\leq b^{k}}$. Multiplying all sides by ${\displaystyle {\frac {b}{(b-1)^{k}}}}$, we get ${\displaystyle {\left({\frac {b}{b-1}}\right)}^{k}\leq bk\leq b{\left({\frac {b}{b-1}}\right)}^{k}}$, or equivalently, ${\displaystyle k\leq {\left({\frac {b}{b-1}}\right)}^{k}\leq bk}$. Since ${\displaystyle {\frac {b}{b-1}}\geq 1}$, this means that there will be a maximum value ${\displaystyle k}$ where ${\displaystyle {\left({\frac {b}{b-1}}\right)}^{k}\leq bk}$, because of the exponential nature of ${\displaystyle {\left({\frac {b}{b-1}}\right)}^{k}}$ and the linearity of ${\displaystyle bk}$. Beyond this value ${\displaystyle k}$, ${\displaystyle F_{b}(n)\leq n}$ always. Thus, there are a finite number of narcissistic numbers, and any natural number is guaranteed to reach a periodic point or a fixed point less than ${\displaystyle b^{k}-1}$, making it a preperiodic point. Setting ${\displaystyle b}$ equal to 10 shows that the largest narcissistic number in base 10 must be less than ${\displaystyle 10^{60}}$.[1]

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

A base ${\displaystyle b}$ has at least one two-digit narcissistic number if and only if ${\displaystyle b^{2}+1}$ is not prime, and the number of two-digit narcissistic numbers in base ${\displaystyle b}$ equals ${\displaystyle \tau (b^{2}+1)-2}$, where ${\displaystyle \tau (n)}$ is the number of positive divisors of ${\displaystyle b}$.

Every base ${\displaystyle b\geq 3}$ that is not a multiple of nine has at least one three-digit narcissistic number. The bases that do not are

2, 72, 90, 108, 153, 270, 423, 450, 531, 558, 630, 648, 738, 1044, 1098, 1125, 1224, 1242, 1287, 1440, 1503, 1566, 1611, 1620, 1800, 1935, ... (sequence A248970 in the OEIS)

There are only 88 narcissistic numbers in base 10, of which the largest is

115,132,219,018,763,992,565,095,597,973,971,522,401

with 39 digits.[1]

## Narcissistic numbers and cycles of Fb for specific b

All numbers are represented in base ${\displaystyle b}$.

${\displaystyle b}$ Narcissistic numbers Cycles Comments
2 0, 1 ${\displaystyle \varnothing }$
3 0, 1, 2, 12, 22, 122 ${\displaystyle \varnothing }$
4 0, 1, 2, 3, 130, 131, 203, 223, 313, 332, 1103, 3303 (sequence A010344 and A010343 in OEIS) ${\displaystyle \varnothing }$
5 0, 1, 2, 3, 4, 23, 33, 103, 433, 2124, 2403, 3134, 124030, 124031, 242423

1234 → 2404 → 4103 → 2323 → 1234

3424 → 4414 → 11034 → 20034 → 20144 → 31311 → 3424

1044302 → 2110314 → 1044302

1043300 → 1131014 → 1043300

6 0, 1, 2, 3, 4, 5, 243, 514, 14340, 14341, 14432, 23520, 23521, 44405, 435152, 5435254, 12222215, 555435035 ...

44 → 52 → 45 → 105 → 330 → 130 → 44

13345 → 33244 → 15514 → 53404 → 41024 → 13345

14523 → 32253 → 25003 → 23424 → 14523

2245352 → 3431045 → 2245352

12444435 → 22045351 → 30145020 → 13531231 → 12444435

115531430 → 230104215 → 115531430

225435342 → 235501040 → 225435342

For ${\displaystyle n\leq 10067135_{10}=555435035_{6}}$
7
8 0, 1, 2, 3, 4, 5, 6, 7, 24, 64, 134, 205, 463, 660, 661, ... (sequence A010354 and A010351 in OEIS)
9
10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, ... (sequence A005188 in the OEIS)
11
12 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, 25, A5, 577, 668, A83, ... (sequence A161949 in the OEIS)
13
14
15
16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 156, 173, 208, 248, 285, 4A5, 5B0, 5B1, 60B, 64B, ... (sequence A161953 in the OEIS)

## Extension to negative integers

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

## Programming example

The example below implements the narcissistic function described in the definition above to search for narcissistic functions and cycles in Python.

def ppdif(x, b):
y = x
digit_count = 0
while y > 0:
digit_count = digit_count + 1
y = y // b
total = 0
while x > 0:
total = total + pow(x % b, digit_count)
x = x // b

def ppdif_cycle(x, b):
seen = []
while x not in seen:
seen.append(x)
x = ppdif(x, b)
cycle = []
while x not in cycle:
cycle.append(x)
x = ppdif(x, b)
return cycle