/* 水仙花数 输出100-999中的所有水仙花数。若三位数ABC满足ABC=A^3+B^3+C^3,则 称其为水仙花数。例如:153 = 1^3 + 5^3 + 3^3,故153是水仙花数. */ # define LOCAL #include<stdio.h> #include<math.h> int main(){ #ifdef LOCAL freopen("data.in","r", stdin); freopen("data.out","w", stdout); #endif // LOCAL for(int i=100;i<1000;i++){ if(pow(i%10,3) + pow(i/10%10,3) + pow(i/100%10,3) == i){ printf("%d ",i); } } return 0; } /* output: 153 370 371 407 */