水仙花数(Narcissistic number)也被称为超完全数字不变数(pluperfect digital invariant, PPDI)、自恋数、自幂数、阿姆斯壮数或阿姆斯特朗数(Armstrong number),水仙花数是指一个 n 位数(n≥3 ),它的每个位上的数字的 n 次幂之和等于它本身(例如:1^3 + 5^3+ 3^3 = 153)。
求所有3位数字的水仙花数。
#include<bits/stdc++.h>
using namespace std;
int main(){
for(int i=1;i<10;i++){
for(int j=0;j<10;j++){
for(int k=0;k<10;k++) //三位数字做循环遍历,百分位至少为1
if(i*i*i+j*j*j+k*k*k==i*100+j*10+k) //数学公式
cout<<i<<j<<k<<endl;
}
}
return 0;
}