原题链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1015
思路:打表二分即可,唯一的可能取到的四位水仙花数可特判
AC代码:
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1000005;
int a[MAXN], t, n;
int main() {
int k = 0;
for (int i = 100; i <= 999; i++) {
if ((i / 100)*(i / 100)*(i / 100) + ((i % 100) / 10)*((i % 100) / 10)*((i % 100) / 10) + (i % 10)*(i % 10)*(i % 10) == i)a[k++] = i;
}
int n;
scanf("%d", &n);
if (n > 407) {
printf("1634\n");
}
else {
printf("%d\n", *lower_bound(a, a + k, n));
}
return 0;
}