pow(a,e,n)不适用于输入pow(1,3,3)

2024-05-29 02:55:24 发布

您现在位置:Python中文网/ 问答频道 /正文

当我使用这些参数(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}$

Tags: inhomelibusrlocalipythonintegerconsole
2条回答

您实现的模幂平方算法应该使用整数。在

e = e/2返回一个有理数3/2。在

您应该将其转换为一个整数e = (e/2).floor()。在

a = (a*a) % n

a=1*1%1 a->0 什么意思是你的案子是0,所以这里

^{pr2}$

你将有0%3。在

编辑: 在python中可以执行3/2%3吗?在

相关问题 更多 >

    热门问题