POJ 2527 polynomial remains polynomial operation

Source: Internet
Author: User

Polynomial remains
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 1236 Accepted: 700

Description

Given the polynomial
A (x) = an xn + ... + A1 X + a0,
Compute the remainder R (x) when a (x) was divided by xk+1.

Input

The input consists of a number of cases. The first line of all case specifies the 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.

Output

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.

Assume that the coefficients of the remainder can is represented by 32-bit integers.

Sample Input

5 26 3 3 2 0 15 20 0 3 2 0 14 11 4 1 1 16 32 3-3 4 1 0 11 05 10 073 51 2 3 4-1-1

Sample Output

3 2-3 -1-2-1 2-3001 2 3 4

Source

Alberta Collegiate Programming Contest 2003.10.18

AC Code

#include <iostream> #include <cstring> #include <cstdio>using namespace Std;int main () {    int n,k;    int my[10000+10];    while (cin>>n>>k) {        if (n==-1&&k==-1) break;        for (int i=0;i<=n;i++) cin>>my[i];        for (int i=n;i>0;--i) cout<<my[i]<< "x^" <<i<< ' + ';        cout<<my[0]<< ' \12 ';        for (int i=n;i>=k;--i) {            if (my[i]==0) continue;            My[i-k]=my[i-k]-my[i];            my[i]=0;        }        int len=n;        while (Len>=0&&!my[len]) len--;        for (int i=0;i<len;++i) cout<<my[i]<< ";        cout<<my[len]<< ' \12 ';    }    return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

POJ 2527 polynomial remains polynomial operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.