您的位置:首页 > 其它

CF #262 (Div. 2)B

2014-08-27 07:45 190 查看
B. Little Dima and Equation

time limit per test
1 second

memory limit per test
256 megabytes

input
standard input

output
standard output
题目链接:http://codeforces.com/contest/460/problem/B

Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.

Find all integer solutions x (0 < x < 109) of
the equation:
x = b·s(x)a + c, 

where a, b, c are
some predetermined constant values and function s(x) determines the sum of all digits in the decimal representation of number x.

The teacher gives this problem to Dima for each lesson. He changes only the parameters of the equation: a, b, c.
Dima got sick of getting bad marks and he asks you to help him solve this challenging problem.

Input

The first line contains three space-separated integers: a, b, c (1 ≤ a ≤ 5; 1 ≤ b ≤ 10000;  - 10000 ≤ c ≤ 10000).

Output

Print integer n — the number of the solutions that you've found. Next print n integers
in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than 109.

Sample test(s)

input
3 2 8


output
3
10 2008 13726


input
1 2 -18


output
0


input
2 2 -1


output
4
1 31 337 967





解题思路:

题意是求满足x = b * s(x)^a + c 的所有x值,并且升序输出。s(x)为x的各个位加起来的和。

首先考虑如果枚举x的话·····运算量太大····但是我们可以枚举s(x),因为s(x)最大是81·····

即一个九位数每一位都是9······于是开始正常枚举,如果所得结果x比1e9大,那就continue,否则

存入数组。最后把数组里的数排下序输出即可。








完整代码:

#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

#pragma comment(linker, "/STACK:102400000,102400000")

typedef long long LL;
typedef double DB;
typedef unsigned uint;
typedef unsigned long long uLL;

/** Constant List .. **/ //{

const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;
int s[100001];
int main()
{
    #ifdef DoubleQ
    freopen("in.txt","r",stdin);
    #endif
    int a , b , c;
    while(~scanf("%d%d%d",&a,&b,&c))
    {
        memset(s , 0 , sizeof(s));
        int t = 0;
        for(int i = 1 ; i <= 81 ; i ++)
        {
            LL cnt = 1;
            for(int j = 0 ; j < a ; j ++)
                cnt *= i;
            LL tmp = cnt * b + c;
            int res = 0;
            LL tmp2 = tmp;
            if(tmp2 > 1e9)
                continue;
            while(tmp2)
            {
                res += tmp2 % 10;
                tmp2 /= 10;
            }
            if(res == i)
                s[t++] = tmp;
        }
        printf("%d\n",t);
        sort(s , s + t);
        for(int i = 0 ;  i < t ; i ++)
            printf("%d%c", s[i] , i == t - 1 ? '\n' : ' ');
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: