codevs 3943 数学奇才琪露诺

本文针对CodeVS3943的数学奇才琪露诺题目进行了深入分析,通过枚举数位和的方法解决了L,R≤10^9条件下的问题,提供了一种有效求解策略。

二次联通门 : codevs 3943 数学奇才琪露诺

 

 

 

 

/*
    codevs 3943 数学奇才琪露诺
    
    一眼看过去
    感觉这道题是个神题。。。不可做(MMP,什么时候⑨题成这样了)
    
    后来打了个暴力, 0分
    
    再后来仔细想了想
    既然L,R<=10^9
    那么数位之和最大就到81 (999999999)
    那么直接枚举数位和来分解就好了。。。 
*/
#include <cstdio>

#define Limit 81

void read (int &now)
{
    register char word = getchar ();
    bool temp = false;
    for (now = 0; word < '0' || word > '9'; word = getchar ())
        if (word == '-')
            temp = true;
    for (; word <= '9' && word >= '0'; now = now * 10 + word - '0', word = getchar ());
    if (temp)
        now = -now;
}

int K, P, Q;
int L, R;

long long Fast_Pow (long long x, int p)
{
    long long res = 1;
    for (; p; p >>= 1)
    {
        if (p & 1)
            res = res * x;
        x = x * x;
    }
    return res;
}

long long Carculate (int x)
{
    return (long long) Fast_Pow ((long long) x, K) * P;
}

#define Max 10000000
int data[Max];
int Cur;

int Need;

int main (int argc, char *argv[])
{
    read (K);
    read (P);
    read (Q);
    read (L);
    read (R);
    
    register long long now, res;
    for (register int i = 1; i <= Limit; i ++)
    {
        now = Carculate (i) + Q;
        
        int key = 0;
        res = now;
        if (now <= R && now >= L)
        {
            for (; now; key += now % 10, now /= 10);
            if (key == i)
                data[++ Cur] = res;
        }
    }
    printf ("%d\n", Cur);
    for (int i = 1; i <= Cur; i ++)
        printf ("%d ", data[i]);
    return 0;
}

 

转载于:https://www.cnblogs.com/ZlycerQan/p/7197503.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值