UVa 10719 Quotient Polynomial (mathematics)

Source: Internet
Author: User
Tags printf time limit

10719-quotient polynomial

Time limit:3.000 seconds

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem &problem=1660

A polynomial of degree n can be expressed as

If k is any integer then we can write:

Here q (x) is called the quotient polynomial of p (x) of degree (n-1) and R are any Integ Er which is called the remainder.

For example, if p (x) = x3 -7x2+ 15x-8 and k = 3 then q (x) = x2 -4x + 3 and r = 1. Again if p (x) = x3 -7x2+ 15x-9 and k = 3 then q (x) = x2 -4x + 3< /c11> and r = 0.

In this problem your have to find the quotient polynomial q (x) and the remainder R. All the input and output data would fit in 32-bit signed integer.

Input
Your program should accept a even number of lines of text. Each pair of line would represent one test case. The ' I ' would contain an integer value of K. The second line would contain a list of integers (an, an-1, ... a0), which repres ENT the set of co-efficient of a polynomial p (x). Here 1≤n≤10000. The Input is terminated by <eof>.

Output
for each pair of the lines, your program should print exactly two. The should contain the coefficients of the quotient polynomial. Print the reminder in second line. There is a blank spaces before and after the ' = ' sign. Print a blank line after the output of each test case. For exact format, follow the given sample.

Train of thought: Q (x) In addition to the maximum coefficient of the highest term and P (x) the same coefficient, the other coefficients have a law q[i] = p[i] + k * Q[i-1]. (Use large Division card)

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Complete code:

/*0.089s*/
  
#include <cstdio>
  
int p[10010], q[10010];
  
int main (void)
{
    int k, n;
    char c;
    while (~SCANF ("%d", &k))
    {
        c = 1;
        for (n = 0; c!= ' \ n '; n++)
            scanf ("%d%c", &p[n), &c);
        Q[0] = p[0];
        for (int i = 1; i < n; i++)
            q[i] = p[i] + k * Q[i-1];
        printf ("Q (x):");
        for (int i = 0; i < n-1 i++)
            printf ("%d", Q[i]);
        printf ("\nr =%d\n\n", q[n-1]);
    }
    return 0;
}

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.