B. Little Dima and Equation

来源:互联网 发布:淘宝卖家地址怎么看 编辑:程序博客网 时间:2024/05/22 03:38

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)  |||||  (我第一次就是在这里出错的!!! 没有注意x的范围) of the equation:

x = b·s(x)a + c, 

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

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 printn integers in the increasing order — the solutions of the given equation. Print only integer solutions that are larger than zero and strictly less than109.

 

s(1000)=1

s(999999999)=81

思路出来的有木有!   1->81  枚举 s(x)  然后得到  x  再进行判断。

注意:1,x  在计算时的范围会超过 int        10000*81^5+10000;

           2,   x  也是有范围的  x (0 < x < 109)


//B#include<iostream>#include<cstdio>using namespace std;//---------------------------------int S(long long int x){    int ans=0;    while(x>0)    {        ans+=x%10;        x/=10;    }return ans;}//--------------------------------long long int g(int x,int a){    int i;long long int ans=1;    if(a==0)    {        ans=1;    }    else    {        for(i=1;i<=a;i++)        {            ans*=x;        }    }return ans;}//--------------------------------int main (){    int sx,i,a,b,c;    long long int ans[100000],ans_num,x;    while(~scanf("%d%d%d",&a,&b,&c))    {        ans_num=0;        for(sx=1;sx<=99;sx++)        {            x=b*g(sx,a)+c;            if(sx==S(x))            {if(x>=1000000000)                    // 这里。。。。。;else{ans[ans_num]=x;ans_num++; }            }            else                ;        }        if(ans_num==0)            cout<<0<<endl;        else        {            cout<<ans_num<<endl;            for(i=0;i<ans_num;i++)                //printf("%I64d ",ans[i]);            cout<<ans[i]<<" ";printf("\n");        }    }return 0;}


          


0 0
原创粉丝点击