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-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的更多相关文章
- Codeforces 934.D A Determined Cleanup
D. A Determined Cleanup time limit per test 1 second memory limit per test 256 megabytes input stand ...
- [Codeforces 933B]A Determined Cleanup
Description 题库链接 给你两个正整数 \(p,k\) ,询问是否能够构造多项式 \(f(x)=\sum\limits_{i=0}^{d-1}a_ix^i\) ,使得存在多项式 \(q(x) ...
- Codeforces 934D - A Determined Cleanup
934D - A Determined Cleanup 思路: 找规律,和k进制的求法差不多,答案的奇数位是p%k,偶数位如果p%k!=0,那么答案是k-p%k,否则为0. 代码: #include& ...
- 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 ...
- [codeforces934D]A Determined Cleanup
[codeforces934D]A Determined Cleanup 试题描述 In order to put away old things and welcome a fresh new ye ...
- Codeforces Round #464 (Div. 2) A Determined Cleanup
A. Love Triangle time limit per test1 second memory limit per test256 megabytes Problem Description ...
- 【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 用多项式除法除 ...
- codeforces 462div.2
A A Compatible Pair standard input/output 1 s, 256 MB x1916 B A Prosperous Lot standard input/out ...
- Codeforces水题集合[14/未完待续]
Codeforces Round #371 (Div. 2) A. Meeting of Old Friends |B. Filya and Homework A. Meeting of Old Fr ...
随机推荐
- Spring的 @ExceptionHandler注解无效问题
如果你想设置了@ExceptionHandler注解进行异常捕获返回异常信息,但是Debug调试时,代码并未进到被@ExceptionHandler注解标注的方法里,那么就检查你的配置文件是否包含 & ...
- HTML5来了,7个混合式移动开发框架
在这个时间开始学习移动开发真是最好不过了,每个人应该都有一些移动应用的创意,而且你并不需要任何的原生应用编程经验,你只需要一些HTML的相关知识,懂一些CSS和JavaScript就够了.如果你总听别 ...
- bzoj 1635: [Usaco2007 Jan]Tallest Cow 最高的牛【差分】
s[i]为差分后的"i这头牛前有几头比它高",计算答案的时候加成前缀和,假设第一头最高减一下即可 用map记录一下被加过的区间,避免重复 #include<iostream& ...
- 【转】@Controller和@RestController的区别
知识点:@RestController注解相当于@ResponseBody + @Controller合在一起的作用. 1) 如果只是使用@RestController注解Controller,则Co ...
- 同余模定理 HDOJ 5373 The shortest problem
题目传送门 /* 题意:题目讲的很清楚:When n=123 and t=3 then we can get 123->1236->123612->12361215.要求t次操作后, ...
- 用Movie显示gif(2)GifView
1,类 import android.annotation.SuppressLint; import android.content.Context; import android.content.r ...
- EditText(7)EditText输入事件监听
EditText.addTextChangedListener(TextWatcher watcher); void initSearch(){ search = (EditText) findVie ...
- (2)麻省理工:计算机科学和 Python 编程导论
语义描述了我们如何从那些表达式中推导出相关的含义,从而解决我们想解决的问题. 语法描述了如何将合法表达式组合在一起. 我们要选择什么样的编程语言? 1. 不管我们选什么,都有如下过程: 输入信 ...
- QT开发之旅-Udp聊天室编程
一.概要设计 登录对话框(继承自QDialog类)进行用户登录查询数据库用户是否存在,注册插入数据到用户表.用户表字段: (chatid int primary key, passwd varchar ...
- Server 2008 R2 事件查看器实现日志分析
在 windows server 2008 R2 中,可以通过点击 "开始" -> "管理工具" -> "事件查看器" ,来打开 ...