/* Print out all the "Narcissus number", the so-called "Narcissus number" refers to a three-digit, its members of the digital cubic and equal to the number itself. For example: 153 is a "narcissus number", because of the three of the 153=1 +5 of the three square +3 of three times because of 100 200 300 500 400 The whole hundred is not a narcissus can be directly excluded and 101 is not the basis of the Narcissus can be directly excluded from these two laws to eliminate the direct skip calculation * *Public classNarcissus {/* Start run time 1524629170834 153 370 371 407 End Run time 1524629170838 time-consuming: 4 because there are 18 skipped meters The cubic method avoids the redundancy of the computational steps, so it runs faster.Public voidPrintnarcissus () { for(inti = 102; I < 999; i++) {if(i% = 0 | | | I% 101 = 0)Continue;intj = i/100, k = i/10%, z = i% 10;if(i = = Math.pow (j, 3) + Math.pow (k, 3) + Math.pow (z, 3)) System. out. println (i); /** * Traditional algorithm Run results * <p> * Start run time 1524629049929 * Narcissus number is: 153 * Narcissus number is: 370 * Narcissus number is: 371 * Narcissus number is: 407 * End Run time 1524629049949 * Time-consuming: 21 *Public voidSS () { for(intNumber = 100; Number <= 999; number++) {intGewei = number% 10;intShiwei = number/10% 10;intBaiwei = number/100% 10;if(Gewei * Gewei * gewei + Shiwei * Shiwei * shiwei + baiwei * Baiwei * Baiwei = number) {System. out. println ("The number of daffodils is:"+ number); }
}
}
}