您的位置:首页 > 其它

Codeforces Round #262 (Div. 2) B. Little Dima and Equation

2015-08-20 21:37 405 查看
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 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.

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的各位和等于S(X)。

对公式分析。由于X的值<1e9所以,S(x)和最大为81即999999999.注意计算时不要超出数据给的范围。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<cmath>
#include<algorithm>
#define LL  __int64
#define inf 0x3f3f3f3f
using namespace std;
LL p[1000000];
int main()
{
   LL n,m,i,j,k,x,y,pp;
   LL a,b,c;
    while(~scanf("%I64d %I64d %I64d",&a,&b,&c))
    {
        y=0;
        for(i=1;i<=81;i++)
        {
            pp=1;
            for(j=1;j<=a;j++)//有些注成败的细节要注意,pow尽量少和整形数据运算容易数据丢失
            pp*=i;
            x=b*pp+c;
            k=x;
            LL ans=0;
            while(x)
            {
                ans+=x%10;
                x/=10;
            }
            if(ans==i&&k>=1&&k<1e9)//注意运算结果在给定的范围内
            {
                p[y++]=k;
            }
        }
        printf("%I64d\n",y);<span id="transmark"></span>//%I64d<span id="transmark"></span>
        for(i=0;i<y;i++)
        i==y-1?printf("%I64d\n",p[i]):printf("%I64d ",p[i]);
    }
    return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: