阿姆斯特朗数又称水仙花数,是指一种三位数,其各个数字之立方和等于该数。
Armstrong number which is also called Daffodils number is a three-figure number,and the sum of the number of it’s respective positions equals itself.
For example 153 = 1*1*1 + 5*5*5 + 3*3*3
代码
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,g,s,b,m=0;
cin>>n;
for(int i=1;i<=n;i++)
{
b=i/100%10;
s=i/10%10;
g=i%10;
if(b*b*b+s*s*s+g*g*g==i)
m=m+1;
}
cout<<m-1<<endl;
return 0;
}