1.1.4G水仙花数

包子 2020-12-13 1:39:55 2020-12-13 1:44:36

#include<stdio.h>

int a=1;

int main()

{

int sum,g,s,bb,q,w,sw;

while(a<=1000000)

{

	if(a<=9)

	{

		printf("%d ",a);

	}

	else if(a<=99)

	{

		g=a%10;

		s=(a-g)/10;

		sum=g*g+s*s;

		if(sum==a) printf("%d ",sum);

	}

	else if(a<=999)

	{

		g=a%10;

		s=(a%100-g)/10;

		bb=(a-g-s)/100;

		sum=g*g*g+s*s*s+bb*bb*bb;

		if(sum==a) printf("%d ",sum);

	}

	else if(a<=9999)

	{

		g=a%10;

		s=(a%100-g)/10;

		bb=(a%1000-g-s)/100;

		q=(a-bb)/1000;

		sum=g*g*g*g+s*s*s*s+bb*bb*bb*bb+q*q*q*q;

		if(sum==a) printf("%d ",sum);

	}

	else if(a<=99999)

	{

		g=a%10;

		s=(a%100-g)/10;

		bb=(a%1000-g-s)/100;

		q=(a%10000-g-s-bb)/1000;

		w=(a-q)/10000;

		sum=g*g*g*g*g+s*s*s*s*s+bb*bb*bb*bb*bb+q*q*q*q*q+w*w*w*w*w;

		if(sum==a) printf("%d ",sum);

	}

	else if(a<=999999)

	{

		g=a%10;

		s=(a%100-g)/10;

		bb=(a%1000-g-s)/100;

		q=(a%10000-g-s-bb)/1000;

		w=(a%100000-g-s-bb-q)/10000;

		sw=(a-w)/100000;

		sum=g*g*g*g*g*g+s*s*s*s*s*s+bb*bb*bb*bb*bb*bb+q*q*q*q*q*q+w*w*w*w*w*w+sw*sw*sw*sw*sw*sw;

		if(sum==a) printf("%d ",sum);

	}

	a++;

}

return 0;

}