10719 - Quotient Polynomial

题目:10719 - Quotient Polynomial


题目大意:就是给一个多项式,和 k,求除以(x- k)的商和余数。


解题思路:多项式的系数 si, 商的系数xi,则有这样的关系:x1 = s1; xi = si + k*x(i-1),(1 <= i <= n - 1);余数r = sn + k*x(n-1);


#include<stdio.h>

const int N = 10005;
int s[N], k, count;
char ch;
int main() {
	
	while(scanf("%d%*c", &k) != EOF) {
			
		count = 0;
		int i;
		while(scanf("%d%c", &s[count], &ch) && ch != '\n') {

			count++;
		}
		for(i = 1; i <= count ; i++)
			s[i] += k * s[i - 1];  
		printf("q(x): ");
		for( i = 0; i <= count; i++) {
		
			if(i == count)
				printf("\nr = %d\n", s[i]);
			else
			{
				printf("%d", s[i]);
				if(i != count - 1)
					printf(" ");
			}
		}
		printf("\n");
	}
	return 0;
}


你可能感兴趣的:(10719 - Quotient Polynomial)