Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- # from Polynomial import Polynomial
- import numpy as np
- class Polynomial():
- def __init__(self, arr, p):
- self.arr = arr
- self.arr.reverse()
- self.p = p
- def divide(self, poly):
- return np.polydiv(self.arr, poly.arr)
- def __str__(self):
- return str(np.poly1d(self.arr))
- def main(src_fname, dst_fname):
- with open(src_fname, 'r') as sf, open(dst_fname, 'w+') as df:
- p, n = int(sf.readline()), int(sf.readline())
- g = list(map(int, sf.readline().split()))
- poly = Polynomial(g, p)
- cyclic_arr = [p-1] + [0] * (n-1) + [1]
- cyclic_poly = Polynomial(cyclic_arr, p)
- print(cyclic_poly)
- print(poly)
- quot, rem = cyclic_poly.divide(poly)
- print(quot, rem)
- if __name__ == "__main__":
- if len(sys.argv) != 3:
- print("Usage : python3 ParityCheck.py src-fname dest-fname")
- exit()
- main(sys.argv[1], sys.argv[2])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement