我不断收到错误“ 不能在 math.Pow 的参数中使用(类型 int)作为 float64 类型,不能在 math.Pow 的参数中使用 x(类型 int)作为类型 float64,
无效操作:math.Pow(a, x) % n(float64 和 int 类型不匹配) ”
func pPrime(n int) bool {
var nm1 int = n - 1
var x int = nm1/2
a := 1;
for a < n {
if (math.Pow(a, x)) % n == nm1 {
return true
}
}
return false
}
最佳答案
func powInt(x, y int) int {
return int(math.Pow(float64(x), float64(y)))
}
以防万一您必须重复使用它并保持清洁。
关于go - 如何在 Golang 中将 Math.Pow 与整数一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64108933/