In number theory, a narcissistic number (also known as a pluperfect digital invariant (PPDI), an Armstrong number (after Michael F. Armstrong) or a plus perfect number) in a given number base is a number that is the sum of its own digits each raised to the power of the number of digits.
Definition
Let be a natural number. We define the narcissistic function for base to be the following:
where is the number of digits in the number in base , and
is the value of each digit of the number. A natural number is a narcissistic number if it is a fixed point for , which occurs if . The natural numbers are trivial narcissistic numbers for all , all other narcissistic numbers are nontrivial narcissistic numbers.
For example, the number 153 in base is a narcissistic number, because and .
A natural number is a sociable narcissistic number if it is a periodic point for , where for a positive integer (here is the th iterate of ), and forms a cycle of period . A narcissistic number is a sociable narcissistic number with , and an amicable narcissistic number is a sociable narcissistic number with .
All natural numbers are preperiodic points for , regardless of the base. This is because for any given digit count , the minimum possible value of is , the maximum possible value of is , and the narcissistic function value is . Thus, any narcissistic number must satisfy the inequality . Multiplying all sides by , we get , or equivalently, . Since , this means that there will be a maximum value where , because of the exponential nature of and the linearity of . Beyond this value , 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 , making it a preperiodic point. Setting equal to 10 shows that the largest narcissistic number in base 10 must be less than .
The number of iterations needed for to reach a fixed point is the narcissistic function's persistence of , and undefined if it never reaches a fixed point.
A base has at least one two-digit narcissistic number if and only if is not prime, and the number of two-digit narcissistic numbers in base equals , where is the number of positive divisors of .
Every base 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, ...
There are only 89 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.
Narcissistic numbers and cycles of Fb for specific b
All numbers are represented in base . '#' is the length of each known finite sequence.
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
Python
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 return total
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 cycleThe following Python program determines whether the integer entered is a Narcissistic / Armstrong number or not.def no_of_digits(num): i = 0 while num > 0: num //= 10 i+=1
return i
def required_sum(num): i = no_of_digits(num) s = 0
while num > 0: digit = num % 10 num //= 10 s += pow(digit, i)
return s
num = int(input("Enter number:")) s = required_sum(num)
if s == num: print("Armstrong Number") else: print("Not Armstrong Number")
Java
The following Java program determines whether the integer entered is a Narcissistic / Armstrong number or not.
import java.util.Scanner;
public class ArmstrongNumber {
public static void main(String[] args) {
Scanner in = new Scanner(System.in); System.out.println("Enter a positive integer: "); int number = in.nextInt();
if (isArmstrongNumber(number)) {
System.out.println(number + " is an Armstrong number."); } else { System.out.println(number + " is not an Armstrong number."); } }
public static boolean isArmstrongNumber(int number) {
int sum = 0; String numberString = Integer.toString(number); int numberOfDigits = numberString.length();