Problem Description
“水仙花数”是指一个三位数,它的各位数字的立方和等于其本身,比如:153=1 3+5 3+3 3。
现在要求输出所有在m和n范围内的水仙花数。
Input
Output
如果给定的范围内不存在水仙花数,则输出no;
每个测试实例的输出占一行。
Example Input
100 120 300 380
Example Output
no370 371
#include<stdio.h> int main() { int a,b,c,n,m,i,flag,skip; while(scanf("%d%d",&m,&n)!=EOF) { flag=0,skip=1; for(i=m;i<=n;i++) { a=i/100; b=(i/10)%10; c=i%10; if (i==a*a*a+b*b*b+c*c*c) { if(skip) { skip=0; printf("%d",i); flag=1; } else { printf(" "); printf("%d",i); } } } if(flag==1) printf("\n"); if(flag==0) printf("no\n"); } return 0; }