B - Little Dima and Equation

B - Little Dima and Equation
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

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 abc 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: abc. 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 Input

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。

附AC代码:

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 #include <algorithm>
 5 using namespace std;
 6 long long num[100];
 7 int main()
 8 {
 9     long long a,b,c;
10     while(~scanf("%I64d %I64d %I64d",&a,&b,&c)){
11     long long n,ans=0,i,sum,s,j;
12     long long x,temp;
13         for(i=1;i<=81;i++)//s(x)最大为81 
14     {
15         s=1;
16         for(j=1;j<=a;j++)
17             s*=i;//做a次方运算 
18         x=s*b+c;
19         sum=0;
20         temp=x;
21         while(temp)
22         {
23             sum+=temp%10;
24             temp/=10;
25         }
26         if(sum==i&&x>=1&&x<1e9)//查找x 
27         {
28             num[ans++]=x;
29         }
30     }
31     printf("%I64d\n",ans);
32     if(ans!=0){
33         for(i=0;i<ans-1;i++)
34     {
35         printf("%I64d ",num[i]);
36     }
37     printf("%I64d\n",num[ans-1]);
38     }
39     }
40     
41     return 0;
42 }

 

posted @ 2016-05-14 16:44  Kiven#5197  阅读(187)  评论(0编辑  收藏  举报