洛谷[LnOI2019]长脖子鹿省选模拟赛t1 -> 快速多项式变换

快速多项式

做法:刚拿到此题有点蒙,一开始真没想出来怎么做,于是试着去自己写几个例子。

自己枚举几种情况之后就基本看出来了,其实本题中 n 就是f(m)在m进制下的位数,每项的系数就是f(m)在m进制下对应的数字。

然后。。。


code:

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
//Mystery_Sky
//
#define ll long long
ll m, num[500], a;
int tot;
int main() {
    scanf("%lld %lld", &m, &a);
    while(a) {
        num[++tot] = a % m;
        a /= m;
    }
    printf("%d\n", tot);
    for(int i = 1; i <= tot; i++) printf("%lld ", num[i]);
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/Benjamin-cpp/p/10505818.html