CF460B Little Dima and Equation (水题?

Codeforces Round #262 (Div. 2) B

B - Little Dima and Equation

B. Little Dima and Equation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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,其中s(x)为x的各个位的数字之和。给出a,b,c,求x在1~10^9内的所有解。

题解:枚举s(x),算出来x后看看x和s(x)符不符合,x在不在范围内。因为x<=10^9,所以s(x)为0~81,一下就枚举完了。

注意a<=5,81^5已经超int了,要用long long……血的教训

代码:

 1 //#pragma comment(linker, "/STACK:102400000,102400000")
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<iostream>
 5 #include<cstring>
 6 #include<algorithm>
 7 #include<cmath>
 8 #include<map>
 9 #include<set>
10 #include<stack>
11 #include<queue>
12 using namespace std;
13 #define ll long long
14 #define usll unsigned ll
15 #define mz(array) memset(array, 0, sizeof(array))
16 #define minf(array) memset(array, 0x3f, sizeof(array))
17 #define REP(i,n) for(i=0;i<(n);i++)
18 #define FOR(i,x,n) for(i=(x);i<=(n);i++)
19 #define RD(x) scanf("%d",&x)
20 #define RD2(x,y) scanf("%d%d",&x,&y)
21 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
22 #define WN(x) prllf("%d\n",x);
23 #define RE  freopen("D.in","r",stdin)
24 #define WE  freopen("1biao.out","w",stdout)
25 #define mp make_pair
26 #define pb push_back
27 vector<int>v;
28 int a,b,c;
29 int main(){
30     int i,j;
31     ll k;
32     scanf("%d%d%d",&a,&b,&c);
33     v.clear();
34     for(i=0;i<=81;i++){
35         k=1;
36         REP(j,a)k*=i;
37         ll x=k*b+c;
38         if(x<=0 || x>=1000000000)continue;
39         int y=x,sum=0;
40         while(y){
41             sum+=y%10;
42             y/=10;
43         }
44         if(sum==i)v.pb(x);
45     }
46     int maxi=v.size();
47     printf("%d\n",maxi);
48     if(maxi>0)printf("%d",v[0]);
49     for(i=1;i<maxi;i++)
50         printf(" %d",v[i]);
51     return 0;
52 }

 

posted @ 2014-08-21 20:35  带鱼Yuiffy  阅读(288)  评论(0编辑  收藏  举报