首页 > 其他 > 详细

codevs 3943 数学奇才琪露诺

时间:2017-07-17 23:28:19      阅读:320      评论:0      收藏:0      [点我收藏+]

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

 

 

 

 

/*
    codevs 3943 数学奇才琪露诺
    
    一眼看过去
    感觉这道题是个神题。。。不可做
    
    后来打了个暴力, 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;
}

 

codevs 3943 数学奇才琪露诺

原文:http://www.cnblogs.com/ZlycerQan/p/7197503.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!