import java.util.Scanner;
public class TestDemo3 { //求出0~999999之间的所有水仙花数 public static void waterFlower(int n){ for (int i = 1; i <n ; i++) { //求i是几位数 int sum=0; int count=0;//保存每一位数字的次方 int tmp=i;//记录当前数字的位数 while (tmp!=0){ count++;//1,2,3 tmp=tmp/10;//12,1,0 } tmp =i; //求tmp的每一位数字上的数字 123 while(tmp!=0){ sum=sum+(int)Math.pow(tmp%10,count); //Math.pow(a,b);a^b tmp=tmp/10; } if (sum==i){ System.out.println(i); } } }
public static void main(String[] args) {
Scanner scanner =new Scanner(System.in);
int n=scanner.nextInt();
waterFlower(n);
}
}