P - Polynomial Remains ACM
阿新 • • 發佈:2019-01-06
Description
Given the polynomialcompute the remainder r(x) when a(x) is divided by x k+1.
Input
Output
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
#include <stdio.h> #include <string.h> #include <algorithm> using namespace std; const int N = 10005; int n, k, a[N]; int main () {while (scanf("%d%d", &n, &k) == 2 && n != -1 && k != -1) { for (int i = n; i >= 0; i--) scanf("%d", &a[i]); int t = max(n - k, -1); for (int i = 0; i <= t; i++) a[i+k] -= a[i]; printf("%d", a[n]); for (int i = n - 1; i > t; i--) printf(" %d", a[i]); printf("\n"); } return 0; }