水仙花数是指一个 n 位数 ( n >= 3 ),它的每个位上的数字的 n 次幂之和等于它本身。(例如:1^3 + 5^3 + 3^3 = 153)
给出一个整数M,求 >= M的最小的水仙花数。
输入
一个整数M(10 <= M <= 1000)
输出
输出>= M的最小的水仙花数
输入样例
99
输出样例
153
代码:
#include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> #include <algorithm> using namespace std; int n; bool check(int t) { int len = log10(t) + 1; int sum = 0; int tt = t; while(t) { int d = 1; for(int i = 0;i < len;i ++) { d *= t % 10; } sum += d; t /= 10; } return tt == sum; } int main() { scanf("%d",&n); n = max(n,153); while(!check(n)) n ++; printf("%d",n); return 0; }