[Codeforces] 460B - Little Dima and Equation

题意:

x = b·s(x)a + c,  输入a,b,c。 s(x)是x每位数字求和。

从小到大输出符合上述式子的x(0 < x < 1e9)。

思考了一会发现,s(x)的范围很小 0 ~81。

直接枚举s(x)即可。

#include <stdio.h>  
#include <string.h>  
#include <math.h>  
#include <stdlib.h>  
#include <algorithm>  
#include <iostream>  
#include <set>  
#include <map>  
#include <queue>  
#include <stack>
#include <assert.h>
typedef long long LL;
using namespace std;
LL pow(LL t, LL y)
{
    LL tmp = t;
    for(int i = 1; i < y; i++)
    {
        tmp *= t;
    }
    return tmp;
}
int gao(LL t)
{
    int ans = 0;
    while(t)
    {
        ans += t % 10;
        t /= 10;
    }
    return ans;
}
int main()  
{  
    //freopen("test0.in", "r", stdin);  
    //freopen("test0.out", "w", stdout);  
    LL a, b, c, sx, sxb, x, tp[100000], ans;
    while(~scanf("%I64d %I64d %I64d", &a, &b, &c))
    {
        ans = 0;
        for(sx = 0; sx <= 81; sx++)
        {
            sxb = pow(sx, a) * b + c;
            if(sxb > 0 && sxb < 1000000000 && gao(sxb) == sx)
            {
                tp[ans++] = sxb;
            }
        }
        printf("%I64d\n", ans);
        for(int i = 0; i < ans; i++)
        {
            printf(i ? " %I64d":"%I64d", tp[i]);
        }
        printf("\n");
    }
    return 0;  
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值