传送门: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. Python split 分割中文

    str8="中国 和 韩国 的区别" # a=str8.find("Python") # print a b=str8.find("和") ...

  2. 最短路径(Dijkstra算法)

    当用图结构来表示通信.交通等网络,权重代表距离或者成本,寻找最短路径就成为了一个重要的任务. 给定带权网络G=(V;E),源点s,对于其他所有顶点v,寻找s到v的最短路径,连接成一颗最短路径树.可以证 ...

  3. php insteadof 作用

    PHP5的另一个新成员是instdnceof关键字.使用这个关键字可以确定一个对象是类的实例.类的子类,还是实现了某个特定接口,并进行相应的操作.在某些情况下,我们希望确定某个类是否特定的类型,或者是 ...

  4. nat模式下更改网络环境, 虚拟机中Linux无法上网的问题

    出现的问题: 1.ifconfig -a 命令下会出现eth0信息中无ip地址等等信息: 2.无法ping通baidu,也就是无法上网: 3.ping 8.8.8.8 提示 connect:netwo ...

  5. mui 文件上传注意问题

    1. mui 文件上传 key对应后台接收参数名,但对对于多文件上传就没办法了,addFile 的key不能重复 task.addFile( "_www/a.doc", {key: ...

  6. ROS-USB摄像头

    前言:演示使用usb摄像头功能,推荐使用方法二. 首先要有一个usb摄像头,本次使用的是罗技(Logitech)摄像头. 一.使用软件库里的uvc-camera功能包 1.1 检查摄像头 lsusb ...

  7. 题解报告:hdu 1061 Rightmost Digit(快速幂取模)

    Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...

  8. C# 调用非托管函数

    C#通过DllImport可以直接调用Windows中的一些功能.C++中已经编写好的一些方法: DllImport所在的名字空间:System.Runtime.InteropServices; Dl ...

  9. Spring: (一) -- 春雨润物之 核心IOC

    作为一个Java人,想必都或多或少的了解过Spring.对于其优势也能道个一二,诸如方便解耦.支持AOP编程.支持声明式事务.方便测试等等.Spring也不仅仅局限于服务器端开发,它可以做非常多的事情 ...

  10. LN : leetcode 231 Power of Two

    lc 231 Power of Two 231 Power of Two Given an integer, write a function to determine if it is a powe ...