zoukankan      html  css  js  c++  java
  • [Codeforces 933B]A Determined Cleanup

    Description

    题库链接

    给你两个正整数 (p,k) ,询问是否能够构造多项式 (f(x)=sumlimits_{i=0}^{d-1}a_ix^i) ,使得存在多项式 (q(x)) ,满足 (f(x)=q(x)cdot(x+k)+p) 。且 (a_iin[0,k),iin [0,d))

    (1leq pleq 10^{18},2leq kleq 2000)

    Solution

    我们假设 (q(x)=sumlimits_{i=0}^{d-2}b_ix^i) ,那么存在 [egin{aligned}a_0&=kb_0+p\a_1&=kb_1+b_0\&vdots\a_{d-2}&=kb_{d-2}+b_{d-3}\a_{d-1}&=b_{d-2}end{aligned}]

    逐步从下往上递推,最终我们可以得到 (p=sumlimits_{i=0}^{d-1} (-k)^ia_i) 。显然 (p_{(10)}=overline{a_{d-1}cdots a_1a_0}_{(-k)}) ,做一遍进制转换就好了。

    Code

    //It is made by Awson on 2018.2.17
    #include <bits/stdc++.h>
    #define LL long long
    #define dob complex<double>
    #define Abs(a) ((a) < 0 ? (-(a)) : (a))
    #define Max(a, b) ((a) > (b) ? (a) : (b))
    #define Min(a, b) ((a) < (b) ? (a) : (b))
    #define Swap(a, b) ((a) ^= (b), (b) ^= (a), (a) ^= (b))
    #define writeln(x) (write(x), putchar('
    '))
    #define lowbit(x) ((x)&(-(x)))
    using namespace std;
    void read(LL &x) {
        char ch; bool flag = 0;
        for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
        for (x = 0; isdigit(ch); x = (x<<1)+(x<<3)+ch-48, ch = getchar());
        x *= 1-2*flag;
    }
    void print(LL x) {if (x > 9) print(x/10); putchar(x%10+48); }
    void write(LL x) {if (x < 0) putchar('-'); print(Abs(x)); }
    
    LL p, k, a[10005], d;
    
    void work() {
        read(p), read(k); k = -k;
        while (p) {
            a[++d] = p%k, p /= k; 
            if (a[d] < 0) a[d] = -k+a[d], p++;
        }
        writeln(d);
        for (int i = 1; i <= d; i++) write(a[i]), putchar(' ');
    }
    int main() {
        work(); return 0;
    }
  • 相关阅读:
    docker构建镜像
    SpringBoot 配置的加载
    Gradle实战(02)--Gradle Build的创建
    Gradle实战(01)--介绍与安装
    统计最常用10个命令的脚本
    jackson序列化与反序列化的应用实践
    go http请求流程分析
    java线程的3种实现方式及线程池
    git多账号使用
    java多版本管理
  • 原文地址:https://www.cnblogs.com/NaVi-Awson/p/8451912.html
Copyright © 2011-2022 走看看