一、什么是水仙花数?
水仙花数(Narcissistic number)也被称为超完全数字不变数(pluperfect digital invariant,PPDL)、自恋数、自幂数、阿姆斯壮数或阿姆斯特朗数(Armstrong number),水仙花数是指一个3位数,它的每个位数上的数字的3次幂之和等于它本身(例如:1^3+5^3+3^3=153,则153是一个水仙花数)。
在数论中,水仙花数(Narcissistic number)也称为自恋数、自幂数、阿姆斯壮数或阿姆斯特朗数(Armstrong number),是指一N位数,其各个数之N次方和等于该数。
例如153、370、371及407就是三位数的水仙花数,其各个数之立方和等于该数:
153 = 1^3 + 5^3 + 3^3。
370 = 3^3 + 7^3 + 0^3。
371 = 3^3 + 7^3 + 1^3。
407 = 4^3 + 0^3 + 7^3。
二、定义
水仙花数只是自幂数的一种,严格来说,只有3位数的3次幂数才能称为水仙花数。
常见的水仙花:
三位的水仙花数共有4个:153,370,371,407;
四位的四叶玫瑰数共有3个:1634,8208,9474;
五位的五角星数共有3个:54748,92727,93084;
六位的六合数只有1个:548834;
七位的北斗七星数共有4个:1741725,4210818,9800817,9926315;
八位的八仙数共有3个:24678050,24678051,88593477
三、0~999之间所有水仙花数的求取
1.代码段
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i, j, a, b, c;
int count = 0;
for (i = 100; i <= 999; i++)
{
a = i / 100;
b = (i % 100) / 10;
c = i % 10;
j = a*a*a + b*b*b + c*c*c;
if (i == j)
{
count++;
printf("%d\n", i);
}
}
printf("\n水仙花数的个数为count=%d\n", count);
system("pause");
return 0;
}
2.运行结果