HDU 2010 水仙花数 2
1 #include<stdio.h> 2 int IsNarcissus(int n) 3 { 4 int i,j,k; 5 i=n/100; 6 j=n/10%10; 7 k=n%10; 8 if(n==i*i*i+j*j*j+k*k*k) return 1; 9 return 0; 10 } 11 int main(int m,int n) 12 { 13 while(~scanf("%d%d",&m,&n)) 14 { 15 while(!IsNarcissus(m)&&m<=n) m++; 16 if(m<=n) printf("%d",m); 17 else{ 18 printf("no\n"); 19 continue; 20 } 21 while(m<n) 22 if(IsNarcissus(++m)) 23 printf(" %d",m); 24 printf("\n"); 25 } 26 return 0; 27 }