传送门:http://codeforces.com/contest/934/problem/D

给定两个正整数p(p≥1)、k(k>1)。多项式f(x)的系数的取值集合为{0,1,2,...,k-1},且存在多项式q(x),s.t.f(x)=q(x)·(x+k)+p。求多项式f(x)。

设$f(x)=\sum_{i=0}^{n}a_i x^i$,$q(x)=\sum_{i=0}^{n-1}b_i x^i$,则:$f(x)=q(x)\cdot(x+k)+p=kb_0+p+\sum_{i=1}^{n-1}(kb_i+b_{i-1})x^i+b_{n-1}x^n$。于是,

$$a_i=\begin{cases} kb_0+p,i=0\\kb_i+b_{i-1},1\le i<n\\b_{n-1},i=n\end{cases}$$

由于0≤ai<k,于是,

$$b_i=\begin{cases} \left\lceil-\frac{p}{k}\right\rceil,i=0\\\left\lceil-\frac{b_{i-1}}{k}\right\rceil,1\le i<n\end{cases}$$

即可确定多项式系数。参考程序如下:

#include <stdio.h>
#include <stdint.h>
#define MAX_N 10000 int64_t a[MAX_N], b[MAX_N]; int64_t ceil_div(int64_t x, int64_t y)
{
int64_t res = x / y;
if (x > && x % y) res++;
return res;
} int main(void)
{
int64_t p, k;
scanf("%I64d%I64d", &p, &k);
int d = ;
b[] = ceil_div(-p, k);
a[] = k * b[] + p;
for (int i = ; i < MAX_N; i++) {
b[i] = ceil_div(-b[i - ], k);
a[i] = k * b[i] + b[i - ];
if (a[i]) d = i + ;
}
printf("%d\n", d);
for (int i = ; i < d; i++)
printf("%d ", a[i]);
return ;
}

Codeforces 934D/933B - A Determined Cleanup的更多相关文章

  1. Codeforces 934.D A Determined Cleanup

    D. A Determined Cleanup time limit per test 1 second memory limit per test 256 megabytes input stand ...

  2. [Codeforces 933B]A Determined Cleanup

    Description 题库链接 给你两个正整数 \(p,k\) ,询问是否能够构造多项式 \(f(x)=\sum\limits_{i=0}^{d-1}a_ix^i\) ,使得存在多项式 \(q(x) ...

  3. Codeforces 934D - A Determined Cleanup

    934D - A Determined Cleanup 思路: 找规律,和k进制的求法差不多,答案的奇数位是p%k,偶数位如果p%k!=0,那么答案是k-p%k,否则为0. 代码: #include& ...

  4. Codeforces Round #462 (Div. 2) D. A Determined Cleanup

    D. A Determined Cleanup time limit per test1 second memory limit per test256 megabytes Problem Descr ...

  5. [codeforces934D]A Determined Cleanup

    [codeforces934D]A Determined Cleanup 试题描述 In order to put away old things and welcome a fresh new ye ...

  6. Codeforces Round #464 (Div. 2) A Determined Cleanup

    A. Love Triangle time limit per test1 second memory limit per test256 megabytes Problem Description ...

  7. 【Codeforces Round #462 (Div. 1) B】A Determined Cleanup

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 设\(设f(x)=a_d*x^{d}+a_{d-1}*x^{d-1}+...+a_1*x+a_0\) 用它去除x+k 用多项式除法除 ...

  8. codeforces 462div.2

    A A Compatible Pair standard input/output 1 s, 256 MB    x1916 B A Prosperous Lot standard input/out ...

  9. Codeforces水题集合[14/未完待续]

    Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework A. Meeting of Old Fr ...

随机推荐

  1. js获取下拉框当前选中的值并弹出

    this.options[this.selectedIndex].value --- 显示文本 this.value --- 实际存储值 调用实例: <script language=" ...

  2. vue 简介

    Vue.js是一套构建用户界面的渐进式框架.采用自底向上增量开发的设计.Vue的核心值关注视图层非常容易与其他库和已有的项目整合.另外,Vue完全有能力驱动采用单文件组件和Vue生态系统支持的库开发复 ...

  3. uva11542

    https://vjudge.net/problem/UVA-11542 xor高斯消元... 答案为2^f-1 其实书上有一个问题 样例有3种情况,其中4,6,15是绑在一起的,也就是他们必须满足一 ...

  4. node.js开发错误——DeprecationWarning: Mongoose: mpromise

    原文地址 使用mongoose进行数据库操作时,总是提示: (node:5684) DeprecationWarning: Mongoose: mpromise (mongoose's default ...

  5. mysql数据类型和java对应表(copy)

    [说明] 资料来自:http://dev.mysql.com/doc/connector-j/5.1/en/connector-j-reference-type-conversions.html My ...

  6. 牛客OI周赛2-提高组

    A.游戏 链接:https://www.nowcoder.com/acm/contest/210/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语 ...

  7. 国王游戏 2012年NOIP全国联赛提高组(贪心+高精)

    P1080 国王游戏 题目描述 恰逢 H 国国庆,国王邀请 n 位大臣来玩一个有奖游戏.首先,他让每个大臣在左.右手上面分别写下一个整数,国王自己也在左.右手上各写一个整数.然后,让这 n 位大臣排成 ...

  8. robotframework - Run标签

    1.下面是Run标签的截图 2.Run 标签上的按钮和输入框的作用: 1) Execution Profile:选择运行方式,里面有 pybot.jybot 和 custom script.其中我们默 ...

  9. extjs grid禁止表格头部使用鼠标拖拽改变宽度

    extjs6 经典版 表格头部使用鼠标拖动 禁止改变列的宽度 只需要给grid 设置属性enableColumnResize:false就可以啦 xtype:'grid', enableColumnR ...

  10. JOptionPane.showMessageDialog出现在浏览器下面的解决方法

    将JOptionPane.showMessageDialog(null, result, "发布公告:", JOptionPane.INFORMATION_MESSAGE);中的参 ...