喇叭花数是这样的三位数,其每一位数字的阶乘之和恰好等于它本身,即abc = a! + b! + c!,其中,abc表示一个三位数。
<script>
/*喇叭花数*/
/*求出阶乘*/
function factor(number)
{
var factorial = 1;
for(var i = 1; i <= number; i++)
{
factorial *= i;
}
return factorial;
}
for(var i = 100; i <= 999; i++)
{
var str = i.toString();
var hund = parseInt(str.charAt(0));
var ten = parseInt(str.charAt(1));
var unit = parseInt(str.charAt(2));
if(factor(hund) + factor(ten) + factor(unit) == i)
{
console.log(i);
}
}
</script>