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. qt中控件的使用函数

    1.Text Edit编辑框 //将编辑框中的内容转化成Utf8编码 ui->textEdit->toPlainText().toUtf8(); 2.Combo Box下拉框的应用 (1) ...

  2. c语言第一次作业——输入与输出格式

    一.PTA实验作业 1.温度转换 本题要求编写程序,计算华氏温度150°F对应的摄氏温度.计算公式:C=5×(F−32)/9,式中:C表示摄氏温度,F表示华氏温度,输出数据要求为整型. 1.实验代码 ...

  3. 20162327WJH程序设计与数据结构第七周总结

    学号 20162327 <程序设计与数据结构>第7周学习总结 教材学习内容总结 1.关于接口的理解:接口可以理解为比较纯粹的抽象类 2.接口的特点:用interface定义接口 接口中的方 ...

  4. XML使用练习

    #!/usr/bin/env python # -*- coding:utf-8 -*- import requests from xml.etree import ElementTree as ET ...

  5. Java HashMap工作原理及实现

    Java HashMap工作原理及实现 2016/03/20 | 分类: 基础技术 | 0 条评论 | 标签: HASHMAP 分享到:3 原文出处: Yikun 1. 概述 从本文你可以学习到: 什 ...

  6. 第十二条:考虑实现Comparable接口

    与前面讨论的方法不同,compareTo()方法并没有在Object类中定义.相反,它是Comparable接口中唯一的方法. 一个类的实例对象要想是可以比较大小的,那么这个类需要实现Comparab ...

  7. [Android]上传到多个Maven仓库的Gradle插件RapidMavenPushPlugin

    博客搬迁至https://blog.wangjiegulu.com RSS订阅:https://blog.wangjiegulu.com/feed.xml RapidMavenPushPlugin 用 ...

  8. Vim 中文社区:期待你的加入

    我们的愿景 Vim 中文社区一直比较零散,缺少凝聚力,现有的一些群经常也是水的可以的,讨论各种无关紧要的内容,于是导致很大一部分人,将这些群丢入了群助手,渐渐地他们也淡出了 vim 中文社区. 而我理 ...

  9. python解释NTFS runlist的代码(文章转自北亚数据恢复张宇工程师)

    代码如下: 执行效果如下:root@zhangyu-VirtualBox:~/NTFS-5# python3 read_runlist.py mft_source.img ***参数数量或格式错误! ...

  10. wyh的数列~(坑爹题目)

    链接:https://www.nowcoder.com/acm/contest/93/K来源:牛客网 题目描述 wyh学长特别喜欢斐波那契数列,F(0)=0,F(1)=1,F(n)=F(n-1)+F( ...