100 120 300 380
#include<stdio.h> int main() { int m,n,i,a,b,c,d; int x[100]; while(scanf("%d%d",&m,&n)!=EOF) { d=0; 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) { x[d]=i; d++; } } if(d==0) printf("no\n"); else { for(i=0;i<d;i++) { if(i!=d-1) printf("%d ",x[i]); else printf("%d\n",x[i]); } } } return 0; }//C++#include <iostream> using namespace std; int main() { int m,n,a,b,c,i; while(cin>>m>>n) { bool flag = true ; for(i=0;m<=n;m++) { a=m/100; b=m/10%10; c=m%10; if(m==a*a*a+b*b*b+c*c*c) { if(flag) { cout<<m; flag=false ; } else cout<<" "<<m; i++; } } if(i==0) cout<<"no"<<endl; else cout<<endl; } return 0; }
原文:http://blog.csdn.net/phytn/article/details/38277263