Description
Input
Sample Input
输入1:
3
-2 5 -4 1
输入2:
4
8 -20 18 -7 1
输入3:
2
2 -3 1
Output
Sample Output
输出1:
1 1 2
输出2:
1 2 2 2
输出3 :
1 2
Data Constraint
题解
首先我们知道一个n次方程一定可以分解成(x-x1)(x-x2)……(x-xp)的形式
那么我们每次先找出一个最小的可以满足当前方程的解
然后用大除法把(x-xk)的项去掉
重复做n次就可以了
贴代码
var
a:array[0..10]of int64;
b:array[0..10]of int64;
i,j,k,n,now:longint;
x,y,z,p,t:int64;
begin
assign(input,'equation.in'); reset(input);
assign(output,'equation.out'); rewrite(output);
readln(n);
for i:=1 to n+1 do read(a[i]);
x:=0;
for i:=n+1 downto 1 do
begin
b[i]:=a[x+1];
inc(x);
end;
now:=n+1;
for i:=1 to n do
begin
for j:=1 to 20 do
begin
x:=0;
y:=1;
for k:=now downto 1 do
begin
x:=x+b[k]*y;
y:=y*j;
end;
if x=0 then break;
end;
write(j,' ');
x:=now-1;
t:=j;
p:=0;
fillchar(a,sizeof(a),0);
for j:=1 to now-1 do
begin
p:=b[j]-p;
a[j]:=p;
p:=-t*p;
end;
b:=a;
dec(now);
end;
close(input); close(output);
end.