This commit is contained in:
parent
769375e69e
commit
8851473c6e
2 changed files with 14 additions and 3 deletions
15
modp.py
15
modp.py
|
@ -24,4 +24,17 @@ class ModP(int):
|
||||||
|
|
||||||
def _inv(self):
|
def _inv(self):
|
||||||
'Find multiplicative inverse of self in Z mod p.'
|
'Find multiplicative inverse of self in Z mod p.'
|
||||||
pass
|
# extended Euclidean algorithm
|
||||||
|
rcurr = self.p
|
||||||
|
rnext = int(self)
|
||||||
|
tcurr = 0
|
||||||
|
tnext = 1
|
||||||
|
|
||||||
|
while rnext:
|
||||||
|
q = rcurr // rnext
|
||||||
|
rcurr, rnext = rnext, rcurr - q * rnext
|
||||||
|
tcurr, tnext = tnext, tcurr - q * tnext
|
||||||
|
|
||||||
|
if rcurr != 1:
|
||||||
|
raise ValueError("%d not a unit modulo %d" % (self, self.p))
|
||||||
|
return ModP(self.p, tcurr)
|
2
padic.py
2
padic.py
|
@ -31,8 +31,6 @@ class PAdic:
|
||||||
return int(self.get(32), p)
|
return int(self.get(32), p)
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.get(32)
|
return self.get(32)
|
||||||
def __repr__(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
# arithmetic operations
|
# arithmetic operations
|
||||||
def __add__(self, other):
|
def __add__(self, other):
|
||||||
|
|
Loading…
Reference in a new issue