Problem F: Polynomial Remains

Given the polynomial

      a(x) = an xn + ... + a1 x + a0,

compute the remainder r(x) when a(x) is divided by xk+1.

The input consists of a number of cases. The first line of each case specifies the two integers n and k (0 ≤ n, k ≤ 10000). The next n+1 integers give the coefficients of a(x), starting from a0 and ending with an. The input is terminated if n = k = -1.

For each case, output the coefficients of the remainder on one line, starting from the constant coefficient r0. If the remainder is 0, print only the constant coefficient. Otherwise, print only the first d+1 coefficients for a remainder of degree d. Separate the coefficients by a single space.

You may assume that the coefficients of the remainder can be represented by 32-bit integers.

Sample Input

5 2
6 3 3 2 0 1
5 2
0 0 3 2 0 1
4 1
1 4 1 1 1
6 3
2 3 -3 4 1 0 1
1 0
5 1
0 0
7
3 5
1 2 3 4
-1 -1

Sample Output

3 2
-3 -1
-2
-1 2 -3
0
0
1 2 3 4 题意已标黄,即求出一元n次多项式除以x^k+1后的余数,若余数为0,则输出0;否则,从0次幂系数r0开始输出最后一个不为0的系数。
按照除法的模拟过程模拟即可。简单说一下模拟过程: 比如
5 2
6 3 3 2 0 1
多项式除以x^k+1后,x大于等于k的幂的系数均变为0。比如若使x^5系数变为0,则需要(x^2+1)*(6*x^3) = 6*x^5 + 6*x^3;这样就可以将原多项式的5次幂项减掉,顺带着,3次幂项系数会减6;由此规律,每抵消掉一个x次幂,其x-2次幂的系数会相应减少x次幂的系数。这样一直到使x的k次幂系数为0就好了。这样代码就很好写了。
 #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
const int N = ;
int n, k, c[N], i;
int main() {
while (~scanf("%d%d", &n, &k) && n != - || k != -)
{
for (i = ; i <= n; i++)
scanf("%d", &c[i]);
for (i = n; i >= k; i--)
{
c[i - k] -= c[i];
c[i] = ;
}
i = n;
while (c[i] == && i >= ) i--;
if (i == -) printf("0\n");
else {
printf("%d", c[]);
for (int j = ; j <= i; j++)
printf(" %d", c[j]);
printf("\n");
}
}
return ;
}

【数论】UVa 10586 - Polynomial Remains的更多相关文章

  1. UVA 10951 - Polynomial GCD(数论)

    UVA 10951 - Polynomial GCD 题目链接 题意:给定两个多项式,求多项式的gcd,要求首项次数为1,多项式中的运算都%n,而且n为素数. 思路:和gcd基本一样,仅仅只是传入的是 ...

  2. uva 10951 - Polynomial GCD(欧几里得)

    题目链接:uva 10951 - Polynomial GCD 题目大意:给出n和两个多项式,求两个多项式在全部操作均模n的情况下最大公约数是多少. 解题思路:欧几里得算法,就是为多项式这个数据类型重 ...

  3. 数论 UVA 10780

    数论题目.有关内容:整数质因数分解,N的阶乘质因数分解,整除的判断. 这道题的题意是给你两个数n.m,要求你求出n!所能整除的m^k的最大值的k是多少. 由于数据范围:1<m<5000,1 ...

  4. 数论 UVA 10943

    这是一道关于组合数和隔板法的数论题目.题目说的是选出k个不同且不大于N的数字进行相加,要求这些数字之和等于N,结果要求输出这样的数有多少组.这里可以将问题利用隔板法来转换,那么题目的叙述可以转换成:这 ...

  5. 数论 UVA 11889

    有关数论的题目,题目大意是给你两个数a和c,c为a和另一个数b的最小公倍数,要求你求出b的最小值.由最大公约数gcd(a,b)和最小公倍数lcm(a,b)之间的关系可知,lcm(a,b)*gcd(a, ...

  6. 数论 UVA 10791

    这道题目是关于满足同意最小公倍数的所有数对中两数之和的最小值. 题目大意是给你一个数n,要求你求出在所有以n为最小公倍数的数对中两数之和的最小值. 方法:将n进行质因数分解,再将所有分解出的质因子加起 ...

  7. 数论 UVA 11076

    这道题目的意思简单易懂说的是给你n个数(可能有重复相同的数字),列出他们所有排列的情况,再逐位相加,求出和,例如:给你1,2,3,则排列的情况为<123>, <132>, &l ...

  8. 数论 UVA 11752

    题目大意是在1~2^64-1的范围内找到所有符合条件的数,条件要求这个数字是两个或两个以上不同数字的幂,例如64=8^2=4^3. 对于这一题,分析是:如果一个满足这个条件的数字一定可以转换成i^k, ...

  9. 数论 UVA 11388

    这道题是关于两个数的最大公约数和最小公倍数的题目.给你两个数字g,l,分别表示最大公约数和最小公倍数.要求你找到两个数a,b,要求这两个数的最大公约数和最小公倍数为所给的两个数.如果存在多组数字符合这 ...

随机推荐

  1. Could not bind factory to JNDI

    将hibernate.cfg.xml中 <session-factory name="SessionFactory">的name属性去掉即可

  2. 最近的bug列表总结(C++)

    最近写了一大段代码,抽象得厉害,容易绕进去,因为写单测的代价很大(借口),所以很多问题到联调的是否才发现. 而且花费了很大的经历才查出来,主要问题有如下几个问题 1. 变量未初始化 具体来说,就是指针 ...

  3. Spring MVC ControllerClassNameHandlerMapping example

    handler mapping是把url跟控制器关联起来. In Spring MVC, ControllerClassNameHandlerMapping use convention to map ...

  4. C 语言中包含的标准头文件(24个)

    <assert.h><complex.h><ctype.h><errno.h><fenv.h><float.h><intt ...

  5. [iOS微博项目 - 1.0] - 搭建基本框架

    A.搭建基本环境   github: https://github.com/hellovoidworld/HVWWeibo   项目结构:   1.使用代码构建UI,不使用storyboard     ...

  6. hdu4614Vases and Flowers(线段树,段设置,更新时范围的右边值为变量)

    Problem Description Alice is so popular that she can receive many flowers everyday. She has N vases ...

  7. Bootstrap排版

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta na ...

  8. VLAN设置

    A Logical Network is a way of representing networks in your datacenter that have the same connectivi ...

  9. 在Mac OS X 10.9上安装nginx

    1. 安装PCRE Download latest PCRE. After download go to download directory from terminal. $ cd ~/Downlo ...

  10. Educational Codeforces Round 1 A. Tricky Sum 暴力

    A. Tricky Sum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem ...