Description

题库链接

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

\(1\leq p\leq 10^{18},2\leq k\leq 2000\)

Solution

我们假设 \(q(x)=\sum\limits_{i=0}^{d-2}b_ix^i\) ,那么存在 \[\begin{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=\sum\limits_{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('\n'))
#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;
}

[Codeforces 933B]A Determined Cleanup的更多相关文章

  1. Codeforces 934D - A Determined Cleanup

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

  2. Codeforces 934D/933B - A Determined Cleanup

    传送门:http://codeforces.com/contest/934/problem/D 给定两个正整数p(p≥1).k(k>1).多项式f(x)的系数的取值集合为{0,1,2,...,k ...

  3. Codeforces 934.D A Determined Cleanup

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

  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. HIVE的常用操作(HQL)语句

    HIVE基本操作命令 创建数据库 >create database db_name; >create database if not exists db_name;//创建一个不存在的数据 ...

  2. Beta 第六天

    今天遇到的困难: github服务器响应很慢 推图的API接口相应较慢,超过了初始设定的最大延迟时间,导致了无法正确返回图片 ListView滑动删除Demo出现了某些Bug,这些Bug可能导致了某些 ...

  3. RxSwift:ReactiveX for Swift 翻译

    RxSwift:ReactiveX for Swift 翻译 字数1787 阅读269 评论3 喜欢3 图片发自简书App RxSwift | |-LICENSE.md |-README.md |-R ...

  4. DML数据操作语言之查询(一)

    1.select语句基础 基本语句格式:  select <列名>,.... from <表名>; select子句中列举出希望从表中查询出的列的名称,from子句则指定了选取 ...

  5. JAVA_SE基础——37.main方法的详解

    主函数 大家都会写吧. 大家一直都不知道为何这样设计,这样设计有什么好处呢? 白话解释: main函数的修饰符是public: 公共的 为何不用private 等等的修饰符 而规定只用public呢? ...

  6. UDP协议实现客户服务器数据交互

    UDP协议实现客户服务器数据交互 按照往常一样将今天自己写的题目答案写在了博客上习题:客户端循环发送消息给服务端,服务端循环接收,并打印出来,直到收到Bye就退出程序. package network ...

  7. 新特性GTID

    什么是GTID 每提交一个事务,当前的执行过程都会拿到一个唯一的标识符,此标识符不仅对其源mysql 实列是唯一的而在给定的复制环境中的所有mysql 实列也是唯一的,所哟的事务与其GTID 之间都是 ...

  8. Python内置函数(1)——abs

    英文文档: abs(x) Return the absolute value of a number. The argument may be an integer or a floating poi ...

  9. kubernetes入门(07)kubernetes的核心概念(4)

    一.pod 二.Volume volume可以为容器提供持久化存储,比如 三.私有镜像 在使用私有镜像时,需要创建一个docker registry secret,并在容器中引用.创建docker r ...

  10. kafka HA

    1. replication 如图.1所示,同一个 partition 可能会有多个 replica(对应 server.properties 配置中的 default.replication.fac ...