首页 > 代码库 > codevs 3943 数学奇才琪露诺

codevs 3943 数学奇才琪露诺

二次联通门 : 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 数学奇才琪露诺