x의 범위는 1부터 10^9사이의 값이라 확인하기 어렵지만 s(x)값은 1부터 81까지의 수밖에 나오지 않는다. s(x)값을 전부 확인하면서 이 때의 x값을 다시 만들어보고 x와 b x s(x)^a + c의 값이 일치하는 지 확인한다.
대회 중 이 문제를 많이 틀렸고 원인을 못 찾았는데 알고보니 최댓값인 10^9를 10e^9라 표현해서 문제였다. e^9가 10^9과 같은데 여기에 10을 곱해서 10^10이 되었다. 앞으로 주의해서 풀어봐야겠다.
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#define xx first
#define yy second
#define MAX 1e9
using namespace std;
using i64 = long long;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
int make(string s)
{
int sum = 0;
for (int i = 0; i < s.size(); i++)
{
if (s[i] == '-')
continue;
sum += s[i] - '0';
}
return sum;
}
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
vector<int> ans;
for (int i = 1; i <= 81; i++)
{
i64 res = 1;
for (int j = 0; j < a; j++)
res *= i;
res *= b;
res += c;
if (0 < res && res < MAX)
{
if(make(to_string(res)) == i)
ans.push_back(res);
}
}
sort(ans.begin(), ans.end());
printf("%d\n", ans.size());
for (int i = 0; i < ans.size(); i++)
printf("%d ", ans[i]);
return 0;
}
'prompt' 카테고리의 다른 글
[토요라운드] 20/09/05 후기 (0) | 2020.09.05 |
---|---|
[Special Round 2] C. 작업 일지 (0) | 2020.07.18 |
[Special Round 2] A. 장난감 분류 (0) | 2020.07.18 |
[코드포스 Round 80] B. Buying Shovels (0) | 2020.07.06 |
[코드포스 Round 80] A. Board Moves (0) | 2020.07.06 |