当我使用这些参数(pow(1,3,3)),为什么会得到这个错误消息?公司名称:
sage: pow(1,3,3)
3
3/2
3/2
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
/home/kai/<ipython console> in <module>()
/home/kai/<ipython console> in pow(a, e, n)
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/rings/rational.so in sage.rings.rational.Rational.__mod__ (sage/rings/rational.c:19891)()
/usr/lib/sagemath/local/lib/python2.7/site-packages/sage/rings/integer.so in sage.rings.integer.Integer.inverse_mod (sage/rings/integer.c:32726)()
ZeroDivisionError: Inverse does not exist.
战俘():
^{pr2}$
您实现的模幂平方算法应该使用整数。在
e = e/2
返回一个有理数3/2
。在您应该将其转换为一个整数
e = (e/2).floor()
。在a=1*1%1 a->0 什么意思是你的案子是0,所以这里
^{pr2}$你将有0%3。在
编辑: 在python中可以执行3/2%3吗?在
相关问题 更多 >
编程相关推荐