title: CodeForces 460B Little Dima and Equation 枚举
date: 2016-08-03 19:33:29
tags:
- 枚举
- CodeForces
Little Dima and Equation
题意:
给出a,b,c,求满足x = b·s(x)^a + c的x有哪些。
s(x)是x每一位之和
思路:
由于x不超过1e9,所以s(x)最大是81,枚举1到81计算s(x)是否相等即可
#include<bits/stdc++.h>
using namespace std;
const long long MAXN = 1e9;
long long ans[10000000];
long long s(long long x)
{
long long d = 0;
while(x)
{
d += x%10;
x /= 10;
}
return d;
}
int main(int argc, char const *argv[])
{
long long a, b, c;
//freopen("in.txt", "r", stdin);
while(~scanf("%I64d%I64d%I64d", &a, &b, &c))
{
memset(ans, 0, sizeof(ans));
long long cnt = 0;
for (long long i = 1; i<=81; ++i)
{
long long x = 1;
for (long long j = 0; j < a; ++j)
{
x*=i;
}
//printf("i=%d %d
", i, b*x+c);
if(s(b*x+c) == i&&(b*x+c>0)&&(b*x+c<MAXN))
{
ans[cnt++] = b*x+c;
}
}
printf("%I64d
", cnt);
if(cnt)
{
for (int i = 0; i < cnt-1; ++i)
{
printf("%I64d ", ans[i]);
}
printf("%I64d
", ans[cnt-1]);
}
}
return 0;
}