水仙花数指一个三位数,它的个位数字的立方和等于它本身,比如:153=1(3)+5(3)+3(3)
现在要求出所有在m~n范围内的水仙花数。
#include <bits/stdc++.h>
using namespace std;
bool jud(int x){
int s =0,y=x,z;
while(y){
z=y%10;
s=s+z*z*z;
y=y/10;
}
if(s==x)return true;
else return false;
}
int main(){
int m,n;
while (cin>>m>>n){
int flag=0;
for(int i=m;i<=n;i++){
if(jud(i)){
flag=1;
cout<<i<<" ";
}
}
if(!flag) cout<<"no";
cout<<endl;
}
return 0;
}