/* Print out all the "daffodils", the so-called "Narcissus number" refers to a three-digit number, whose numbers are cubic and equal to the number itself. For example: 153 is a "narcissus number", because the 153=1 three square +5 of the three +3-time side three of the square because of 100 200 300 500 400 The whole hundred is not a narcissus can be directly ruled out and 101 for the base is not a narcissus can be directly ruled out the direct skip calculation of these two rules */classNarcissus {/* Start run time 1524629170834 153 370 371 407 End-of-run time 1524629170838 time: 4 because there are 18 skipped meters The cubic method avoids the redundancy of the calculation steps so it runs faster */ FunPrintnarcissus () { for(Iinch102..998) {if(i% = = 0 | | I% 101 = = 0)ContinueValj = i/100Valk = i/10% 10Valz = i% 10if(i.todouble () = = Math.pow (j.todouble (), 3.0) + Math.pow (k.todouble (), 3.0) + Math.pow (z.todouble (), 3.0)) println (i)}}/** * Traditional algorithm Run result * * * start run time 1524629049929 * Daffodil number is: 153 * Narcissus number is : 370 * Narcissus number is: 371 * Narcissus number is: 407 * End of Run time 1524629049949 * Time: 21 * * FunSS () { for(numberinch100..999) {ValGewei = number% 10ValShiwei = number/10% 10ValBaiwei = number/100% 10if(Gewei * Gewei * gewei + Shiwei * Shiwei * shiwei + baiwei * Baiwei * Baiwei = = number) {println ("The number of daffodils is:$Number")
}
}
}
}