水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身

水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身

问题描述:

水仙花数是指一个 n 位数 ( n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身。(例如:1^3 + 5^3+ 3^3 = 153)
输出10000以内的水仙花数

http://zhidao.baidu.com/question/402541959.html

其中1000修改为10000即可

 #include <stdio.h>  
void fun(int n)
{
    if(n<100 || n>1000) return;
    int a,b,c;
    c=n%10;
    b=n/10%10;
    a=n/100%10;
    if(a*a*a+b*b*b+c*c*c == n) printf("%d\n",n);
    fun(n+1);
}
void main()
{
    fun(10000);
}

 #include<stdio.h>
  int three(int x);
  int main()
  {
  int i,j,k,p,n,h,t;
  for (i=0;i<10;i++)
    {
    for (j=0;j<10;j++)
     for (k=0;k<10;k++)
      for (p=1;p<10000;p++)
    if (three(i)+three(j)+three(k)==p)
           {
        h=p/100;
        t=p/10-h*10;
        n=p-h*100-t*10;
           if (h==i&&t==j&&n==k&h!=0&&t!=0&&n!=0)
            {
           printf("%d^3+%d^3+%d^3=%d\n",i,j,k,p);}
        }
      }
     return 0;
     }

    int three(int x)
    {
    int y;
    y=x*x*x;
    return y;
    }

100~999 a^3+b^3+c^3 ==100a+10b+c
1000~9999 a^4+b^4+c^4+d^4 ==1000a+100b+10c+d
10000 a^5+b^5+c^5+d^5+e^5 ==10000a+1000b+100c+10d+c