所以,如果我想使用 pow 函数计算 6^8 mod 5 的值,我应该在一行中输入什么?
假设您不需要先导入它
我知道 pow 的用法是 pow (x, y) = pow (6, 8) = 6^8 和
我的猜测是
mod.pow(6,8)
谢谢!
最佳答案
很简单:pow
有一个可选的第三个参数作为模数。
来自docs :
pow(x, y[, z])
Return x to the power y; if z is present, return x to the power y, modulo z (computed more efficiently than
pow(x, y) % z)
. The two-argument form pow(x, y) is equivalent to using the power operator:x**y
.
所以你想要:
pow(6, 8, 5)
pow(x, y, z)
不仅比 (x ** y) % z
更快更高效,它还可以轻松处理较大的 y
不使用任意精度算法,假设 z
是一个简单的机器整数。
关于python - 使用 pow 函数 python 计算 mod,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32738637/