逐个分解数字判断和是否为本身
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long LL;
- typedef pair<int,int> P;
- const int N=35;
- const double PI=acos(-1);
- #define line '\n'
- #define gt getchar()
- #define mid ((L+R)>>1)
- int read(){int x=0,op=1;char c=gt;while(!isdigit(c)){if(c=='-')op=-1;c=gt;}while(isdigit(c))x=x*10+c-48,c=gt;return x*op;}
- int judge(int x)
- {
- int sum=0;
- while(x)sum+=(x%10)*(x%10)*(x%10),x/=10;
- return sum;
- }
- int main()
- {
- for(int i=100;i<=999;++i)if(judge(i)==i)cout<<i<<line;
- return 0;
- }
来源: http://www.bubuko.com/infodetail-3508172.html