Narcissistic number

Last updated

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 is a number that is the sum of its own digits each raised to the power of the number of digits.

Contents

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 . [1]

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, ... (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 . '#' is the length of each known finite sequence.

Narcissistic numbers#Cycles OEIS sequence(s)
2 0, 12
3 0, 1, 2, 12, 22, 1226
4 0, 1, 2, 3, 130, 131, 203, 223, 313, 332, 1103, 330312 A010344 and A010343
5 0, 1, 2, 3, 4, 23, 33, 103, 433, 2124, 2403, 3134, 124030, 124031, 242423, 434434444, ...18

1234 → 2404 → 4103 → 2323 → 1234

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

1044302 → 2110314 → 1044302

1043300 → 1131014 → 1043300

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

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

A010348
7 0, 1, 2, 3, 4, 5, 6, 13, 34, 44, 63, 250, 251, 305, 505, 12205, 12252, 13350, 13351, 15124, 36034, 205145, 1424553, 1433554, 3126542, 4355653, 6515652, 125543055, ...60 A010350
8 0, 1, 2, 3, 4, 5, 6, 7, 24, 64, 134, 205, 463, 660, 661, 40663, 42710, 42711, 60007, 62047, 636703, 3352072, 3352272, ...63 A010354 and A010351
9 0, 1, 2, 3, 4, 5, 6, 7, 8, 45, 55, 150, 151, 570, 571, 2446, 12036, 12336, 14462, 2225764, 6275850, 6275851, 12742452, ...59 A010353
10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727, 93084, 548834, ...89 A005188
11 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, 56, 66, 105, 307, 708, 966, A06, A64, 8009, 11720, 11721, 12470, ...135 A0161948
12 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, 25, A5, 577, 668, A83, 14765, 938A4, 369862, A2394A, ...88 A161949
13 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, 14, 36, 67, 77, A6, C4, 490, 491, 509, B85, 3964, 22593, 5B350, ...202 A0161950
14 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, 136, 409, 74AB5, 153A632, ...103 A0161951
15 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, 78, 88, C3A, D87, 1774, E819, E829, 7995C, 829BB, A36BC, ...203 A0161952
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, 8C0, 8C1, 99A, AA9, AC3, CA8, E69, EA0, EA1, B8D2, 13579, 2B702, 2B722, 5A07C, 5A47C, C00E0, C00E1, C04E0, C04E1, C60E7, C64E7, C80E0, C80E1, C84E0, C84E1, ...294 A161953

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.

defppdif(x,b):y=xdigit_count=0whiley>0:digit_count=digit_count+1y=y//btotal=0whilex>0:total=total+pow(x%b,digit_count)x=x//breturntotaldefppdif_cycle(x,b):seen=[]whilexnotinseen:seen.append(x)x=ppdif(x,b)cycle=[]whilexnotincycle:cycle.append(x)x=ppdif(x,b)returncycle

The following Python program determines whether the integer entered is a Narcissistic / Armstrong number or not.

defno_of_digits(num):i=0whilenum>0:num//=10i+=1returnidefrequired_sum(num):i=no_of_digits(num)s=0whilenum>0:digit=num%10num//=10s+=pow(digit,i)returnsnum=int(input("Enter number:"))s=required_sum(num)ifs==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.

importjava.util.Scanner;publicclassArmstrongNumber{publicstaticvoidmain(String[]args){Scannerin=newScanner(System.in);System.out.println("Enter a positive integer: ");intnumber=in.nextInt();if(isArmstrongNumber(number)){System.out.println(number+" is an Armstrong number.");}else{System.out.println(number+" is not an Armstrong number.");}}publicstaticbooleanisArmstrongNumber(intnumber){intsum=0;StringnumberString=Integer.toString(number);intnumberOfDigits=numberString.length();for(inti=0;i<numberOfDigits;i++){intdigit=Character.getNumericValue(numberString.charAt(i));sum+=Math.pow(digit,numberOfDigits);}returnsum==number;}}

C#

The following C# program determines whether the integer entered is a Narcissistic / Armstrong number or not.

usingSystem;publicclassProgram{publicstaticvoidMain(){Console.WriteLine("Enter the number:");intvalue=int.Parse(Console.ReadLine());if(value==RequiredSum(value)){Console.WriteLine("Armstrong Number");}else{Console.WriteLine("Not an Armstrong Number");}}privatestaticintCountDigits(intnum){inti=0;for(;num>0;++i)num/=10;returni;}privatestaticintRequiredSum(intnum){intcount=CountDigits(num);intsum=0;while(num>0){sum+=(int)Math.Pow(num%10,count);num/=10;}returnsum;}}

C

The following C program determines whether the integer entered is a Narcissistic / Armstrong number or not.

#include<stdio.h>#include<stdlib.h>#include<stdbool.h>intgetNumberOfDigits(intn);boolisArmstrongNumber(intcandidate);intmain(){intuserNumber=0;printf("Enter a number to verify if it is an Armstrong number: ");scanf("%d",&userNumber);printf("Is %d an Armstrong number?: %s\n",userNumber,isArmstrongNumber(userNumber)?"true":"false");return0;}boolisArmstrongNumber(intcandidate){intnumberOfDigits=getNumberOfDigits(candidate);intsum=0;for(inti=candidate;i!=0;i/=10){intnum=i%10;intn=1;for(intj=0;j<numberOfDigits;j++){n*=num;}sum+=n;}returnsum==candidate;}intgetNumberOfDigits(intn){intsum=0;while(n!=0){n/=10;++sum;}returnsum;}

C++

The following C++ program determines whether the Integer entered is a Narcissistic / Armstrong number or not.

#include<iostream>#include<cmath>boolisArmstrong(intn){//The floor function is redundant because log10(n) + 1 will always be an integer when n is positive. Simply using static_cast<int>(log10(n)) + 1 would suffice.//int digits = floor(log10(n) + 1); //math formula to find number of digits in a number with any baseintsum=0;if(n>=0){intdigits=static_cast<int>(log10(n))+1;for(inttmp=n;tmp;tmp/=10)sum+=pow(tmp%10,digits);}returnsum==n;}intmain(){intn=407;if(isArmstrong(n))std::cout<<n<<" is a narcissistic number\n";elsestd::cout<<n<<" is not a narcissistic number\n";}

Ruby

The following Ruby program determines whether the integer entered is a Narcissistic / Armstrong number or not.

defnarcissistic?(value)#1^3 + 5^3 + 3^3 = 1 + 125 + 27 = 153nvalue=[]nnum=value.to_snnum.each_chardo|num|nvalue<<num.to_iendsum=0i=0whilesum<=valuensum=0nvalue.each_with_indexdo|num,idx|nsum+=num**iendifnsum==valuereturntrueelsei+=1sum+=nsumendendreturnfalseend

JavaScript

The following JavaScript program determines whether the integer entered is a Narcissistic / Armstrong number or not.

functionnarcissistic(number){constnumString=number.toString();constnumDigits=numString.length;letsum=0;for(letdigitofnumString){sum+=Math.pow(parseInt(digit),numDigits);}returnsum===number;}

Rust

The following Rust program prints all the Narcissistic / Armstrong numbers from 0 to 100 million in base 10.

fnis_armstrong_number(num: u64)-> bool{letdigits=num.to_string();digits.chars().map(|x|(xasu64-0x30).pow(digits.len()asu32)).sum::<u64>()==num}fnmain(){(0..100_000_000).for_each(|n|{ifis_armstrong_number(n){println!("{n}")}})}

See also

Related Research Articles

<span class="mw-page-title-main">Binomial coefficient</span> Number of subsets of a given size

In mathematics, the binomial coefficients are the positive integers that occur as coefficients in the binomial theorem. Commonly, a binomial coefficient is indexed by a pair of integers nk ≥ 0 and is written It is the coefficient of the xk term in the polynomial expansion of the binomial power (1 + x)n; this coefficient can be computed by the multiplicative formula

In mathematics, the prime number theorem (PNT) describes the asymptotic distribution of the prime numbers among the positive integers. It formalizes the intuitive idea that primes become less common as they become larger by precisely quantifying the rate at which this occurs. The theorem was proved independently by Jacques Hadamard and Charles Jean de la Vallée Poussin in 1896 using ideas introduced by Bernhard Riemann.

In mathematics, a transcendental number is a real or complex number that is not algebraic – that is, not the root of a non-zero polynomial of finite degree with integer coefficients. The best-known transcendental numbers are π and e. The quality of a number being transcendental is called transcendence.

In number theory, a Liouville number is a real number with the property that, for every positive integer , there exists a pair of integers with such that

<i>p</i>-adic number Number system extending the rational numbers

In number theory, given a prime number p, the p-adic numbers form an extension of the rational numbers which is distinct from the real numbers, though with some similar properties; p-adic numbers can be written in a form similar to decimals, but with digits based on a prime number p rather than ten, and extending to the left rather than to the right.

Elias ω coding or Elias omega coding is a universal code encoding the positive integers developed by Peter Elias. Like Elias gamma coding and Elias delta coding, it works by prefixing the positive integer with a representation of its order of magnitude in a universal code. Unlike those other two codes, however, Elias omega recursively encodes that prefix; thus, they are sometimes known as recursive Elias codes.

In mathematics, the digit sum of a natural number in a given number base is the sum of all its digits. For example, the digit sum of the decimal number would be

Bijective numeration is any numeral system in which every non-negative integer can be represented in exactly one way using a finite string of digits. The name refers to the bijection that exists in this case between the set of non-negative integers and the set of finite strings using a finite set of symbols.

In number theory, a Dudeney number in a given number base is a natural number equal to the perfect cube of another natural number such that the digit sum of the first natural number is equal to the second. The name derives from Henry Dudeney, who noted the existence of these numbers in one of his puzzles, Root Extraction, where a professor in retirement at Colney Hatch postulates this as a general method for root extraction.

A decimal representation of a non-negative real number r is its expression as a sequence of symbols consisting of decimal digits traditionally written with a single separator:

A sum-product number in a given number base is a natural number that is equal to the product of the sum of its digits and the product of its digits.

In number theory, the Erdős–Kac theorem, named after Paul Erdős and Mark Kac, and also known as the fundamental theorem of probabilistic number theory, states that if ω(n) is the number of distinct prime factors of n, then, loosely speaking, the probability distribution of

A non-integer representation uses non-integer numbers as the radix, or base, of a positional numeral system. For a non-integer radix β > 1, the value of

The digital root of a natural number in a given radix is the value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached. For example, in base 10, the digital root of the number 12345 is 6 because the sum of the digits in the number is 1 + 2 + 3 + 4 + 5 = 15, then the addition process is repeated again for the resulting number 15, so that the sum of 1 + 5 equals 6, which is the digital root of that number. In base 10, this is equivalent to taking the remainder upon division by 9, which allows it to be used as a divisibility rule.

A negative base may be used to construct a non-standard positional numeral system. Like other place-value systems, each position holds multiples of the appropriate power of the system's base; but that base is negative—that is to say, the base b is equal to −r for some natural number r.

In number theory, the multiplicative digital root of a natural number in a given number base is found by multiplying the digits of together, then repeating this operation until only a single-digit remains, which is called the multiplicative digital root of . The multiplicative digital root for the first few positive integers are:

In number theory, a factorion in a given number base is a natural number that equals the sum of the factorials of its digits. The name factorion was coined by the author Clifford A. Pickover.

In number theory, a perfect digit-to-digit invariant is a natural number in a given number base that is equal to the sum of its digits each raised to the power of itself. An example in base 10 is 3435, because . The term "Munchausen number" was coined by Dutch mathematician and software engineer Daan van Berkel in 2009, as this evokes the story of Baron Munchausen raising himself up by his own ponytail because each digit is raised to the power of itself.

In number theory and mathematical logic, a Meertens number in a given number base is a natural number that is its own Gödel number. It was named after Lambert Meertens by Richard S. Bird as a present during the celebration of his 25 years at the CWI, Amsterdam.

In number theory, a perfect digital invariant (PDI) is a number in a given number base () that is the sum of its own digits each raised to a given power ().

References

  1. 1 2 3 Weisstein, Eric W. "Narcissistic Number". MathWorld .
  2. Perfect and PluPerfect Digital Invariants Archived 2007-10-10 at the Wayback Machine by Scott Moore
  3. PPDI (Armstrong) Numbers by Harvey Heinz
  4. Armstrong Numbers by Dik T. Winter
  5. Lionel Deimel’s Web Log
  6. (sequence A005188 in the OEIS )