Quotient Polynomial
来源:互联网 发布:龙之信条萝莉捏脸数据 编辑:程序博客网 时间:2024/05/21 22:58
Description
Problem B
Quotient Polynomial
Time Limit
2 Seconds
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 is any integer 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 and r = 0.
In this problem you have to find the quotient polynomial q(x) and the remainder r. All the input and output data will fit in 32-bit signed integer.
Input
Your program should accept an even number of lines of text. Each pair of line will represent one test case. The first line will contain an integer value for k. The second line will contain a list of integers (an, an-1, … a0), which represent the set of co-efficient of a polynomialp(x). Here 1 ≤ n ≤ 10000. Input is terminated by <EOF>.
Output
For each pair of lines, your program should print exactly two lines. The first line should contain the coefficients of the quotient polynomial. Print the reminder in second line. There is a blank space before and after the ‘=’ sign. Print a blank line after the output of each test case. For exact format, follow the given sample.
Sample Input
Output for Sample Input
3
1 –7 15 –8
3
1 –7 15 –9
q(x): 1 -4 3
r = 1
q(x): 1 -4 3
r = 0
这题不难,可以说是水题,值得注意的是输入的形式,你并不知道输入多少数,所以就每读一个数字就读一个字符。。。
1Y。。。
不会的手拿起来模拟一下。。。
#include<stdio.h>int main(){ int i,k,a[10000],b[10000],t; char c; while(scanf("%d",&k)!=EOF) { t=0; for(i=0;;i++) { scanf("%d%c",&a[i],&c); t++; if(c=='\n')break; } b[0]=a[0]; for(i=1;i<t;i++) b[i]=a[i]+b[i-1]*k; printf("q(x):"); for(i=0;i<t-1;i++) printf(" %d",b[i]); printf("\nr = %d\n\n",b[i]); } return 0;}
- Quotient Polynomial
- Quotient Polynomial
- Quotient Polynomial
- Quotient Polynomial
- Quotient Polynomial
- uva 10719 Quotient Polynomial
- uva 10719 - Quotient Polynomial
- 10719 - Quotient Polynomial
- UVa 10719 - Quotient Polynomial
- 10719 - Quotient Polynomial
- Uva 10719 - Quotient Polynomial
- UVa 10719 - Quotient Polynomial
- 10719 - Quotient Polynomial
- UVA 10719 Quotient Polynomial
- UVA10719- Quotient Polynomial
- uva 10719 Quotient Polynomial
- UVa 10719 Quotient Polynomial
- 10719 - Quotient Polynomial
- securecrt + vim + solarized
- Linux Namespace
- tomcat部署web项目的3中方法
- oracle查询当前系统时间
- 【Redis笔记】 第1篇: redis基本概念简介
- Quotient Polynomial
- JAVA框架之Spring【Spring事务详解】
- Multithreading For Performanc
- [转]去掉字符串中重复的字符 --- 华为笔试题
- 网页常见错误代码分析整理
- 黑马程序员_异常
- 从上往下分层打印二叉树
- pig常见错误汇总
- Linux设备模型(二)上层容器