题意:
x = b·s(x)a + c, 输入a,b,c。 s(x)是x每位数字求和。
从小到大输出符合上述式子的x(0 < x < 1e9)。
思考了一会发现,s(x)的范围很小 0 ~81。
直接枚举s(x)即可。
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <assert.h>
typedef long long LL;
using namespace std;
LL pow(LL t, LL y)
{
LL tmp = t;
for(int i = 1; i < y; i++)
{
tmp *= t;
}
return tmp;
}
int gao(LL t)
{
int ans = 0;
while(t)
{
ans += t % 10;
t /= 10;
}
return ans;
}
int main()
{
//freopen("test0.in", "r", stdin);
//freopen("test0.out", "w", stdout);
LL a, b, c, sx, sxb, x, tp[100000], ans;
while(~scanf("%I64d %I64d %I64d", &a, &b, &c))
{
ans = 0;
for(sx = 0; sx <= 81; sx++)
{
sxb = pow(sx, a) * b + c;
if(sxb > 0 && sxb < 1000000000 && gao(sxb) == sx)
{
tp[ans++] = sxb;
}
}
printf("%I64d\n", ans);
for(int i = 0; i < ans; i++)
{
printf(i ? " %I64d":"%I64d", tp[i]);
}
printf("\n");
}
return 0;
}