【数论】UVa 10586 - Polynomial Remains
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 = 10005; int n, k, c , i; int main() { while (~scanf("%d%d", &n, &k) && n != -1 || k != -1) { for (i = 0; i <= n; i++) scanf("%d", &c[i]); for (i = n; i >= k; i--) { c[i - k] -= c[i]; c[i] = 0; } i = n; while (c[i] == 0 && i >= 0) i--; if (i == -1) printf("0\n"); else { printf("%d", c[0]); for (int j = 1; j <= i; j++) printf(" %d", c[j]); printf("\n"); } } return 0; }
- UVA 10586 - Polynomial Remains(数论)
- uva 10586 - Polynomial Remains(数论)
- 数论基础1011 UVA 11754 剩余定理+枚举
- UVA-575-Skew Binary (简单数论问题)
- UVA 571(数论)
- UVA 11426 GCD - Extreme (II) (数论|欧拉函数)
- UVA 10105 Polynomial Coefficients(数论)
- UVA 1415 - Gauss Prime(数论,高斯素数拓展)
- UVa 1363 约瑟夫的数论问题
- uva 11538 - Chess Queen(数论)
- UVA12619 Just Make A Wish 很好的数论题目
- UVA - 1435 Business Cards (数论)
- UVA 10042 Smith Numbers(数论)
- UVA 11916 - Emoogle Grid(数论)
- uva 11728 - Alternate Task(数论)
- UVA 10951 - Polynomial GCD []【数论】
- UVA 1363 - Joseph's Problem(数论)
- UVA-OJ.关于数论的成长练习
- UVa 1642 Magical GCD (暴力+数论)
- UVA 10392 (暑假-数论- G - Factoring Large Numbers)