Multiplying Polynomials by primo

q=eval(raw_input().replace('x','1,').replace(')','),').replace('i','j'))
a=q[0]
for b in q[1:]:e=[[i*j for i in a]for j in b];a=map(sum,zip(e[0]+[0],[0]+e[1]))
j=i=len(a)-1
print'x^'+`i`,
while i:i-=1;print'+-'[(a[~i]+0j).real<0],"%d"%(int(abs(a[~i]))-2*(j-i>9))+"x"*(i>0)+"^%d"%i*(i>1),

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return top