您的位置:首页 > 其它

Codeforces 460B Little Dima and Equation(暴力)

2014-08-31 15:55 309 查看
题目链接:Codeforces 460B Little Dima and Equation

题目大意:给定a,b,c,求有多少x满足公式x=b∗s(x)a+c(s(x)为x的各个位数的累加和)

解题思路:枚举,因为x很大,所以直接枚举s(x)。
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int a, b, c;

ll f (int x) {
ll ret = 1;
for (int i = 0; i < a; i++)
ret *= x;
return ret * b + c;
}

bool judge (int s, int x) {
int ret = 0;
while (x) {
ret += x % 10;
x /= 10;
}
return ret == s;
}

int main () {
vector<int> vec;
scanf("%d%d%d", &a, &b, &c);
for (int i = 1; i <= 81; i++) {
ll u = f(i);
if (u < 1e9 && judge(i, u))
vec.push_back((int)u);
}

sort(vec.begin(), vec.end());
printf("%lu\n", vec.size());
for (int i = 0; i < vec.size(); i++)
printf("%d%c", vec[i], i == vec.size() - 1 ? '\n' : ' ');
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: