小编chi*_*oel的帖子

如何在 Golang 中将 Math.Pow 与整数一起使用

我不断收到错误“不能在 math.Pow 的参数中使用 (type int) 作为 float64 类型,不能在 math.Pow 的参数中使用 x (type 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
}
Run Code Online (Sandbox Code Playgroud)

floating-point integer type-conversion go

3
推荐指数
3
解决办法
4274
查看次数

标签 统计

floating-point ×1

go ×1

integer ×1

type-conversion ×1