问题是2在整数模式环(6)中是不可逆的。我想将结果拆分为2作为普通整数。换句话说,我喜欢摆脱整数模式环的陷阱,将结果带到普通整数,然后将其除以2。
def fast_exponentiation(c, L, q):
Zq = IntegerModRing(q) # create Z_q
g2 = c
result = 1
while True:
y = L % 2
result = Zq(result) * Zq(g2 ** y)
g2 = Zq(g2 * g2)
L = L >> 1
if L == 0:
break
return result
e = fast_exponentiation(2, 4, 6)
print e / 2发布于 2013-11-10 04:36:49
如果要再次将e转换为Integer,您有几个选择:调用Integer (目标对象),或者调用目标父对象ZZ或IntegerRing。
sage: e
1
sage: parent(e)
Ring of integers modulo 6
sage: ZZ(e)
1
sage: parent(ZZ(e))
Integer Ring因此:
sage: e = ZZ(e)
sage: e/2
1/2
sage: e//2
0或者其他你想要的东西。
https://stackoverflow.com/questions/19882606
复制相似问题