#include<stdio.h> #include<stdio.h> #include<string.h> #include<ctype.h> #include<math.h> int power(int x,int n)// 在debug过程中,发现可能会有精度的损失,所以自定义了它。 { int p = 1; while(n--) p*=x; return p; } int fun(int x) { const int value = x; int a[4] = {0}; int i=0; while(x) { a[i++] = x%10; x/=10; } int cnt = i; int sum = 0; for(i = 0; i < cnt; i++) { sum += power(a[i],cnt); } if(sum == value) return 1; else return 0; } int main() { int x; scanf("%3d",&x); int i = 100; for( i = 153; i <= x; i++) { if(fun(i))printf("%d\n",i); } return 0; }
原文:https://www.cnblogs.com/zhang-zsq/p/12573489.html