水仙花数
Description
水仙花数是指一个 n 位数 ( n >= 3 ),它的每个位上的数字的 n 次幂之和等于它本身。(例如:1^3 + 5^3 + 3^3 = 153)
给出一个整数M,求 >= M的最小的水仙花数。
Input
一个整数M(10 <= M <= 1000)
Output
输出>= M的最小的水仙花数
Sample Input
99
Sample Output
153
水题。
#include<iostream>
#include<cmath>
using namespace std;
int judge(int n);
int main()
{
int m;
cin>>m;
for(int i=m;;i++)
{
if(judge(i))
{
cout<<i<<endl;
break;
}
}
return 0;
}
int judge(int n)
{
int temp,res=0,m=(int)log10(n)+1,n2=n;
while(n2)
{
int num=1;
temp=n2%10;
for(int i=1;i<=m;i++)
num=num*temp;
res+=num;
n2/=10;
}
if(res==n) return 1;
return 0;
}