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

解决一道数学惩罚题,寻找满足特定方程的整数解,通过分析方程限制条件及使用循环与条件判断找出所有符合条件的解。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值