Update 'poly.py'
This commit is contained in:
parent
f76cc9e06d
commit
965b5a0394
33
poly.py
33
poly.py
@ -72,35 +72,4 @@ class Polynomial:
|
||||
def gcd(p1, p2):
|
||||
if len(p2.coefficients) == 0:
|
||||
return p1
|
||||
return Polynomial.gcd(p2, Polynomial.divide(p1, p2))
|
||||
|
||||
|
||||
def main():
|
||||
Polynomial.n = int(sys.argv[1])
|
||||
c1 = ast.literal_eval(sys.argv[2])
|
||||
c2 = ast.literal_eval(sys.argv[3])
|
||||
|
||||
f = Polynomial(c1)
|
||||
g = Polynomial(c2)
|
||||
|
||||
ans = []
|
||||
|
||||
mul = Polynomial.multiply(f, g)
|
||||
ans.append(mul.coefficients)
|
||||
|
||||
try:
|
||||
div = Polynomial.divide(f, g)
|
||||
ans.append(div.coefficients)
|
||||
except ZeroDivisionError as e:
|
||||
ans.append(e)
|
||||
|
||||
try:
|
||||
gcd = Polynomial.gcd(f, g)
|
||||
ans.append(gcd.coefficients)
|
||||
except ZeroDivisionError as e:
|
||||
ans.append(e)
|
||||
|
||||
print(ans)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
return Polynomial.gcd(p2, Polynomial.divide(p1, p2))
|
Loading…
Reference in New Issue
Block a user