Overview
In number theory, narcissus numbers (narcissisticnumbers) are also known as Super-full-number invariants (pluperfect digital invariant, ppdi ), Narcissistic number , self-power , Armstrong number , or Armstrong number (Armstrongnumbers), used to describe an N -bit nonnegative integer, The number of its members N times and equals the numbers Themselves.
Example
For example, 153, 370, 371, and 407 are three-bit ultra-complete numbers without variables, the cubic of each number and equal to the Number:
-
153 = 13 + 53 + 33.
-
370 = 33 + 73 + 03.
-
371 = 33 + 73 + 13.
-
407 = 43 + 03 + 73.
Java algorithm
1 /**2 * A narcissistic number is a number which is the sum of the IT own digits each3 * Raised to the power of the number of Digits. e.g., 0, 1, 2, 3, 4, 5, 6, 7, 8,4 * 9, 153, 370, 371, 407, 1634, 8208, 9474.5 */6 public classNarcissisticnumberexample {7 //determine if value is a narcissus number8 public Static BooleanIsnarcissisticnumber (intValue) {9 inttemp =value;Ten intdigits = 0; one //judge value has several numbers, save it in digits a while(temp > 0) { -digits++; -Temp/= 10; the } -temp =value; - intsum = 0; - while(temp > 0) { +Sum + = Math.pow (temp% 10, digits); -Temp/= 10; + } a returnsum = =value; at } - - //start count and end Count - public Static voidPrintnarcissistics (intFromintto ) { - intWhich=0; - for(inti = from; I <= to; i++) in if(isnarcissisticnumber (I)) { -which++; toSystem.out.println ("+which+", "the Number of narcissus" is: "+i); + } - the * } $ Panax Notoginseng //There are several narcissus numbers in 1000. - public Static voidmain (string[] Args) { thePrintnarcissistics (0,1000); + } a the}
Results
The 1th Narcissus number is: 0
The 2nd Narcissus number is: 1
The 3rd Narcissus number Is: 2
The 4th Narcissus number Is: 3
The 5th Narcissus number Is: 4
The 6th Narcissus number Is: 5
The 7th Narcissus number Is: 6
The 8th Narcissus number Is: 7
The 9th Narcissus number Is: 8
The 10th Narcissus number Is: 9
The 11th Narcissus number Is: 153
The 12th Narcissus number Is: 370
The 13th Narcissus number is: 371
The 14th Narcissus number Is: 407
Reference Links:
Wikipedia: https://zh.wikipedia.org/wiki/%E6%B0%B4%E4%BB%99%E8%8A%B1%E6%95%B0
Java for Beginners-narcissistic number:http://primaryjava.blogspot.hk/2013/10/narcissistic-number.html
Number of daffodils in the algorithm (java Language)